Skip to content

Commit 5c62a6c

Browse files
committed
[FAB-9492] Fix flaky discovery cache test
The discovery TestCachePurgeCache sometimes fails because of wrong assumptions of partial cache purging that don't always hold: When the test reaches line 184, the cache (capacity of 4) might have: identity2 identity3 identity4 identity5 and in lines 185-195 we load the cache with: identity1, identity2, identity3, identity4 Therefore, the following scenario might happen: - identity1 is being put, so identity2 is evicted - identity2 is being put, so identity3 is evicted - identity3 is being put, so identity4 is evicted - identity4 is being put, so identity5 is evicted We got 4 evictions so far, in contrast to the (false) assumption of having between 1 and 2. This test changes the identities that are loaded initiality in the warmup phase to 4 instead of 5, and in the next step - we start with identity5 to be sure we evicted some identity, and then only put 2 identities and we just check that the whole cache wasn't purged. Change-Id: If28ae7db4adbc6319d95a3d41e954d8b420c7876 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent e51bd92 commit 5c62a6c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

discovery/authcache_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ func TestCachePurgeCache(t *testing.T) {
169169
cache := newAuthCache(as, authCacheConfig{maxCacheSize: 4, purgeRetentionRatio: 0.75})
170170
as.On("ConfigSequence", "mychannel").Return(uint64(0))
171171

172-
// Warm up the cache - attempt to place 5 identities but the cache size is 4 so among the first 4 identities,
173-
// only 3 of them should be cached
174-
for _, id := range []string{"identity1", "identity2", "identity3", "identity4", "identity5"} {
172+
// Warm up the cache - attempt to place 4 identities to fill it up
173+
for _, id := range []string{"identity1", "identity2", "identity3", "identity4"} {
175174
sd := common.SignedData{
176175
Data: []byte{1, 2, 3},
177176
Identity: []byte(id),
@@ -185,7 +184,7 @@ func TestCachePurgeCache(t *testing.T) {
185184

186185
// Now, ensure that at least 1 of the identities was evicted from the cache, but not all
187186
var evicted int
188-
for _, id := range []string{"identity1", "identity2", "identity3", "identity4"} {
187+
for _, id := range []string{"identity5", "identity1", "identity2"} {
189188
sd := common.SignedData{
190189
Data: []byte{1, 2, 3},
191190
Identity: []byte(id),
@@ -197,7 +196,7 @@ func TestCachePurgeCache(t *testing.T) {
197196
evicted++
198197
}
199198
}
200-
assert.True(t, evicted > 0 && evicted < 3)
199+
assert.True(t, evicted > 0 && evicted < 4, "evicted: %d, but expected between 1 and 3 evictions", evicted)
201200
}
202201

203202
func TestCacheConcurrentConfigUpdate(t *testing.T) {

0 commit comments

Comments
 (0)