From d6d0c18cad6426a0562d19b2b0c66a7c2bb4e2c5 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Mon, 27 May 2019 19:01:04 -0400 Subject: fixed race condition --- cache_test.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'cache_test.go') diff --git a/cache_test.go b/cache_test.go index 82d37c2..cb92c38 100644 --- a/cache_test.go +++ b/cache_test.go @@ -79,17 +79,19 @@ func Benchmark_pushDatabase(b *testing.B) { initDatabase() } - out, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt") - if err != nil { - b.Errorf("Couldn't set up benchmark: %v\n", err) - } + if _, ok := twtxtCache.Users["https://gbmor.dev/twtxt.txt"]; !ok { + out, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt") + if err != nil { + b.Errorf("Couldn't set up benchmark: %v\n", err) + } - statusmap, err := registry.ParseUserTwtxt(out, "gbmor", "https://gbmor.dev/twtxt.txt") - if err != nil { - b.Errorf("Couldn't set up benchmark: %v\n", err) - } + statusmap, err := registry.ParseUserTwtxt(out, "gbmor", "https://gbmor.dev/twtxt.txt") + if err != nil { + b.Errorf("Couldn't set up benchmark: %v\n", err) + } - twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap) + twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap) + } b.ResetTimer() -- cgit 1.4.1-2-gfad0