From 15eb6f4f6da6f9088cceeed3f0288e50ab2255e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=87=95=E5=BD=92=E6=9D=A5?= Date: Tue, 20 May 2025 20:51:50 +0800 Subject: [PATCH] test(hash): modify TestConsistentHashTransferOnFailure to more reasonable test transfer ratio (#4874) --- core/hash/consistenthash_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/hash/consistenthash_test.go b/core/hash/consistenthash_test.go index 329f2c45a..82fd2dbc3 100644 --- a/core/hash/consistenthash_test.go +++ b/core/hash/consistenthash_test.go @@ -86,6 +86,14 @@ func TestConsistentHashIncrementalTransfer(t *testing.T) { func TestConsistentHashTransferOnFailure(t *testing.T) { index := 41 + ratioNotExists := getTransferRatioOnFailure(t, index) + assert.True(t, ratioNotExists == 0, fmt.Sprintf("%d: %f", index, ratioNotExists)) + index = 13 + ratio := getTransferRatioOnFailure(t, index) + assert.True(t, ratio < 2.5/keySize, fmt.Sprintf("%d: %f", index, ratio)) +} + +func getTransferRatioOnFailure(t *testing.T, index int) float32 { keys, newKeys := getKeysBeforeAndAfterFailure(t, "localhost:", index) var transferred int for k, v := range newKeys { @@ -93,14 +101,12 @@ func TestConsistentHashTransferOnFailure(t *testing.T) { transferred++ } } - - ratio := float32(transferred) / float32(requestSize) - assert.True(t, ratio < 2.5/float32(keySize), fmt.Sprintf("%d: %f", index, ratio)) + return float32(transferred) / float32(requestSize) } func TestConsistentHashLeastTransferOnFailure(t *testing.T) { prefix := "localhost:" - index := 41 + index := 13 keys, newKeys := getKeysBeforeAndAfterFailure(t, prefix, index) for k, v := range keys { newV := newKeys[k]