Write deterministic test

This commit is contained in:
Anant Prakash 2018-07-31 15:59:30 +05:30
parent 738f014fcb
commit 15f451bbc1
No known key found for this signature in database
GPG key ID: C5D399F626523045

View file

@ -13,7 +13,6 @@
package cache
import (
"math/rand"
"testing"
"time"
@ -84,17 +83,17 @@ func testRemoveUser(t *testing.T, tCache *TypingCache) {
{"room3", []string{"user1"}},
{"room4", []string{"user1", "user2", "user3"}},
}
for _, tt := range tests {
for _, userID := range tt.userIDs {
tCache.AddTypingUser(userID, tt.roomID, nil)
}
i := rand.Intn(len(tt.userIDs))
tCache.removeUser(tt.userIDs[i], tt.roomID)
expLeftUsers := append(tt.userIDs[:i], tt.userIDs[i+1:]...)
length := len(tt.userIDs)
tCache.removeUser(tt.userIDs[length-1], tt.roomID)
expLeftUsers := tt.userIDs[:length-1]
if leftUsers := tCache.GetTypingUsers(tt.roomID); !test.UnsortedStringSliceEqual(leftUsers, expLeftUsers) {
t.Errorf("Response after removal is unexpected %s/%s", leftUsers, expLeftUsers)
t.Errorf("Response after removal is unexpected. Want = %s, got = %s", leftUsers, expLeftUsers)
}
}
}