MM-31876: Fix racy test GetReplica (#16656)

Automatic Merge
Этот коммит содержится в:
Agniva De Sarker
2021-01-12 19:45:17 +05:30
коммит произвёл GitHub
родитель 356ee8e71a
Коммит d356ef349b

Просмотреть файл

@@ -268,13 +268,13 @@ func TestGetReplica(t *testing.T) {
assert.Len(t, replicas, len(testCase.DataSourceReplicas)) assert.Len(t, replicas, len(testCase.DataSourceReplicas))
for replica := range replicas { for replica := range replicas {
assert.NotEqual(t, store.GetMaster(), replica) assert.NotSame(t, store.GetMaster(), replica)
} }
} else if assert.Len(t, replicas, 1) { } else if assert.Len(t, replicas, 1) {
// Otherwise ensure the replicas contains only the master. // Otherwise ensure the replicas contains only the master.
for replica := range replicas { for replica := range replicas {
assert.Equal(t, store.GetMaster(), replica) assert.Same(t, store.GetMaster(), replica)
} }
} }
@@ -283,20 +283,20 @@ func TestGetReplica(t *testing.T) {
assert.Len(t, searchReplicas, len(testCase.DataSourceSearchReplicas)) assert.Len(t, searchReplicas, len(testCase.DataSourceSearchReplicas))
for searchReplica := range searchReplicas { for searchReplica := range searchReplicas {
assert.NotEqual(t, store.GetMaster(), searchReplica) assert.NotSame(t, store.GetMaster(), searchReplica)
for replica := range replicas { for replica := range replicas {
assert.NotEqual(t, searchReplica, replica) assert.NotSame(t, searchReplica, replica)
} }
} }
} else if len(testCase.DataSourceReplicas) > 0 { } else if len(testCase.DataSourceReplicas) > 0 {
// If no search replicas were defined, but replicas were, ensure they are equal. assert.Equal(t, len(replicas), len(searchReplicas))
assert.Equal(t, replicas, searchReplicas) for k := range replicas {
assert.True(t, searchReplicas[k])
} else if assert.Len(t, searchReplicas, 1) { }
} else if len(testCase.DataSourceReplicas) == 0 && assert.Len(t, searchReplicas, 1) {
// Otherwise ensure the search replicas contains the master. // Otherwise ensure the search replicas contains the master.
for searchReplica := range searchReplicas { for searchReplica := range searchReplicas {
assert.Equal(t, store.GetMaster(), searchReplica) assert.Same(t, store.GetMaster(), searchReplica)
} }
} }
}) })
@@ -330,7 +330,7 @@ func TestGetReplica(t *testing.T) {
} else if assert.Len(t, replicas, 1) { } else if assert.Len(t, replicas, 1) {
// Otherwise ensure the replicas contains only the master. // Otherwise ensure the replicas contains only the master.
for replica := range replicas { for replica := range replicas {
assert.Equal(t, store.GetMaster(), replica) assert.Same(t, store.GetMaster(), replica)
} }
} }
@@ -343,13 +343,14 @@ func TestGetReplica(t *testing.T) {
} }
} else if len(testCase.DataSourceReplicas) > 0 { } else if len(testCase.DataSourceReplicas) > 0 {
// If no search replicas were defined, but replicas were, ensure they are equal. assert.Equal(t, len(replicas), len(searchReplicas))
assert.Equal(t, replicas, searchReplicas) for k := range replicas {
assert.True(t, searchReplicas[k])
}
} else if assert.Len(t, searchReplicas, 1) { } else if assert.Len(t, searchReplicas, 1) {
// Otherwise ensure the search replicas contains the master. // Otherwise ensure the search replicas contains the master.
for searchReplica := range searchReplicas { for searchReplica := range searchReplicas {
assert.Equal(t, store.GetMaster(), searchReplica) assert.Same(t, store.GetMaster(), searchReplica)
} }
} }
}) })