From 8c222e182a4dfc3dda15ba84186a3869d7ffc7ef Mon Sep 17 00:00:00 2001 From: Carl Jackson Date: Sun, 4 Jan 2015 23:42:41 +0100 Subject: [PATCH] Make some sketchy tests Go 1.2 only In particular, these started failing when running tests under the race detector in Go 1.4 [0], probably due to some kind of (GC?) hijinks clearing out the sync.Pool. [0]: these tests might have also failed in 1.3, but I didn't check --- web/middleware12_test.go | 52 ++++++++++++++++++++++++++++++++++++++++ web/middleware_test.go | 44 ---------------------------------- 2 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 web/middleware12_test.go diff --git a/web/middleware12_test.go b/web/middleware12_test.go new file mode 100644 index 0000000..fe5ca9b --- /dev/null +++ b/web/middleware12_test.go @@ -0,0 +1,52 @@ +// +build !go1.3 + +package web + +import "testing" + +// These tests were pretty sketchtacular to start with, but they aren't even +// guaranteed to pass with Go 1.3's sync.Pool. Let's keep them here for now; if +// they start spuriously failing later we can delete them outright. + +func TestCaching(t *testing.T) { + ch := make(chan string) + st := makeStack(ch) + cs1 := st.alloc() + cs2 := st.alloc() + if cs1 == cs2 { + t.Fatal("cs1 and cs2 are the same") + } + st.release(cs2) + cs3 := st.alloc() + if cs2 != cs3 { + t.Fatalf("Expected cs2 to equal cs3") + } + st.release(cs1) + st.release(cs3) + cs4 := st.alloc() + cs5 := st.alloc() + if cs4 != cs1 { + t.Fatal("Expected cs4 to equal cs1") + } + if cs5 != cs3 { + t.Fatal("Expected cs5 to equal cs3") + } +} + +func TestInvalidation(t *testing.T) { + ch := make(chan string) + st := makeStack(ch) + cs1 := st.alloc() + cs2 := st.alloc() + st.release(cs1) + st.invalidate() + cs3 := st.alloc() + if cs3 == cs1 { + t.Fatal("Expected cs3 to be fresh, instead got cs1") + } + st.release(cs2) + cs4 := st.alloc() + if cs4 == cs2 { + t.Fatal("Expected cs4 to be fresh, instead got cs2") + } +} diff --git a/web/middleware_test.go b/web/middleware_test.go index ef36ac9..b262b07 100644 --- a/web/middleware_test.go +++ b/web/middleware_test.go @@ -163,50 +163,6 @@ func TestAbandon(t *testing.T) { assertOrder(t, ch, "one", "router", "end") } -// This is a pretty sketchtacular test -func TestCaching(t *testing.T) { - ch := make(chan string) - st := makeStack(ch) - cs1 := st.alloc() - cs2 := st.alloc() - if cs1 == cs2 { - t.Fatal("cs1 and cs2 are the same") - } - st.release(cs2) - cs3 := st.alloc() - if cs2 != cs3 { - t.Fatalf("Expected cs2 to equal cs3") - } - st.release(cs1) - st.release(cs3) - cs4 := st.alloc() - cs5 := st.alloc() - if cs4 != cs1 { - t.Fatal("Expected cs4 to equal cs1") - } - if cs5 != cs3 { - t.Fatal("Expected cs5 to equal cs3") - } -} - -func TestInvalidation(t *testing.T) { - ch := make(chan string) - st := makeStack(ch) - cs1 := st.alloc() - cs2 := st.alloc() - st.release(cs1) - st.invalidate() - cs3 := st.alloc() - if cs3 == cs1 { - t.Fatal("Expected cs3 to be fresh, instead got cs1") - } - st.release(cs2) - cs4 := st.alloc() - if cs4 == cs2 { - t.Fatal("Expected cs4 to be fresh, instead got cs2") - } -} - func TestContext(t *testing.T) { router := func(c *C, w http.ResponseWriter, r *http.Request) { if c.Env["reqID"].(int) != 2 {