summaryrefslogtreecommitdiffstats
path: root/val_test.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-09-15 11:45:04 -0400
committerSam Anthony <sam@samanthony.xyz>2025-09-15 11:45:04 -0400
commitabdfc41f64938dc77a23e35db2768e46e19f6d18 (patch)
tree651492ebaf9fd3d90834ca2f1f5499ec1d315480 /val_test.go
parenta26dcba10a0d02a2e74784d87d93f5f5e53c5c24 (diff)
downloadshare-master.zip
Diffstat (limited to 'val_test.go')
-rw-r--r--val_test.go24
1 files changed, 18 insertions, 6 deletions
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.