Skip to content

Commit

Permalink
Get and Len are not thread safe
Browse files Browse the repository at this point in the history
Fixes a race condition when checking items inside the prepared
statement cache during tests.
  • Loading branch information
Zariel committed Apr 13, 2015
1 parent 61d083e commit 1f7e822
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,8 @@ func TestPreparedCacheEviction(t *testing.T) {
t.Fatalf("insert into prepcachetest failed, error '%v'", err)
}

stmtsLRU.Lock()

//Make sure the cache size is maintained
if stmtsLRU.lru.Len() != stmtsLRU.lru.MaxEntries {
t.Fatalf("expected cache size of %v, got %v", stmtsLRU.lru.MaxEntries, stmtsLRU.lru.Len())
Expand All @@ -1154,8 +1156,10 @@ func TestPreparedCacheEviction(t *testing.T) {

_, ok = stmtsLRU.lru.Get(session.cfg.Hosts[i] + ":9042gocql_testSELECT id,mod FROM prepcachetest WHERE id = 0")
selEvict = selEvict || !ok

}

stmtsLRU.Unlock()

if !selEvict {
t.Fatalf("expected first select statement to be purged, but statement was found in the cache.")
}
Expand Down

0 comments on commit 1f7e822

Please sign in to comment.