Skip to content

Commit

Permalink
Add test case for race-in-cache exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
rationull committed Jan 4, 2018
1 parent aa82a44 commit f63138c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions 2-race-in-cache/check_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//////////////////////////////////////////////////////////////////////
//
// DO NOT EDIT THIS PART
// Your task is to edit `main.go`
//

package main

import "testing"

func TestMain(t *testing.T) {
cache := run()

cacheLen := len(cache.cache)
pagesLen := cache.pages.Len()
if cacheLen != CacheSize {
t.Errorf("Incorrect cache size %v", cacheLen)
}
if pagesLen != CacheSize {
t.Errorf("Incorrect pages size %v", pagesLen)
}
}
8 changes: 7 additions & 1 deletion 2-race-in-cache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ func (l *Loader) Load(key string) string {
return val
}

func main() {
func run() *KeyStoreCache {
loader := Loader{
DB: GetMockDB(),
}
cache := New(&loader)

RunMockServer(cache)

return cache
}

func main() {
run()
}

0 comments on commit f63138c

Please sign in to comment.