From 2173550bc87857eee443f8f7c49ce17bf348878f Mon Sep 17 00:00:00 2001 From: "sashakoshka@tebibyte.media" Date: Sat, 25 Jan 2025 19:58:51 -0500 Subject: [PATCH] sync: Test idempotency of Gate.Close --- sync/gate_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sync/gate_test.go b/sync/gate_test.go index da41a73..747e9d6 100644 --- a/sync/gate_test.go +++ b/sync/gate_test.go @@ -1,6 +1,7 @@ package usync import "time" +import "errors" import "testing" func TestGate(test *testing.T) { @@ -50,3 +51,13 @@ func TestGateCloseEarly(test *testing.T) { test.Fatal("timed out waiting for sender goroutine to stop") } } + +func TestGateCloseIdempotent(test *testing.T) { + gate := NewGate[int]() + err := gate.Close() + if err != nil { test.Fatal(err) } + err = gate.Close() + if !errors.Is(err, ErrAlreadyClosed) { + test.Fatal("wrong error: ", err) + } +}