From abdfc41f64938dc77a23e35db2768e46e19f6d18 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Mon, 15 Sep 2025 11:45:04 -0400 Subject: deque --- val_test.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'val_test.go') diff --git a/val_test.go b/val_test.go index 5c37d27..b2ac6d6 100644 --- a/val_test.go +++ b/val_test.go @@ -1,6 +1,7 @@ package share_test import ( + "sync" "testing" "github.com/sam-rba/share" @@ -9,29 +10,40 @@ import ( // Set value in local goroutine, verify in remote goroutine. func TestValSetLocal(t *testing.T) { val := "foo" + sharedVal := share.NewVal[string]() sharedVal.Set <- val - verifySameVal(sharedVal, val, t) + defer sharedVal.Close() + + var wg sync.WaitGroup + wg.Add(2) go func() { - defer sharedVal.Close() verifySameVal(sharedVal, val, t) + wg.Done() }() + go func() { + verifySameVal(sharedVal, val, t) + wg.Done() + }() + wg.Wait() } // Set value in remote goroutine, verify in local goroutine. func TestValSetRemote(t *testing.T) { val := "foo" + sharedVal := share.NewVal[string]() defer sharedVal.Close() - done := make(chan bool) - defer close(done) + + var wg sync.WaitGroup + wg.Add(1) go func() { sharedVal.Set <- val verifySameVal(sharedVal, val, t) - done <- true + wg.Done() }() verifySameVal(sharedVal, val, t) - <-done + wg.Wait() } // Val.TryGet() before Set should fail. -- cgit v1.2.3