summaryrefslogtreecommitdiff
path: root/utilities/utilities_test.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2023-04-19 09:44:57 -0400
committerWill Hawkins <[email protected]>2023-04-19 09:44:57 -0400
commite2bdd8109e9d707d30d518f4da334ddc2c747eb0 (patch)
tree370d9e575f108ad263e3338c84caf3731143602c /utilities/utilities_test.go
parentfd658c8e1ac37a770b62d5d5c53dfaaf9db256a6 (diff)
[Bugfix] Probers starting too soon caused panic
In the case where the scheduler allowed a delay between go threads in a particular order, it was possible that a self prober would attempt to use a connection before an HTTP connection was established. Fixes #45. (at least I hope!)
Diffstat (limited to 'utilities/utilities_test.go')
-rw-r--r--utilities/utilities_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/utilities/utilities_test.go b/utilities/utilities_test.go
index 3a84d76..aa66f6b 100644
--- a/utilities/utilities_test.go
+++ b/utilities/utilities_test.go
@@ -14,6 +14,7 @@
package utilities
import (
+ "context"
"log"
"sync"
"testing"
@@ -86,3 +87,32 @@ func TestFilenameAppend(t *testing.T) {
t.Fatalf("%s != %s for FilenameAppend.", expected, result)
}
}
+
+func TestWaitWithContext(t *testing.T) {
+ ctxt, canceller := context.WithCancel(context.Background())
+ never_true := func() bool { return false }
+ mu := sync.Mutex{}
+ cond := sync.NewCond(&mu)
+
+ wg := sync.WaitGroup{}
+
+ wg.Add(3)
+
+ go func() {
+ ContextSignaler(ctxt, 500*time.Millisecond, &never_true, cond)
+ wg.Done()
+ }()
+
+ go func() {
+ WaitWithContext(ctxt, &never_true, &mu, cond)
+ wg.Done()
+ }()
+
+ go func() {
+ time.Sleep(2 * time.Second)
+ canceller()
+ wg.Done()
+ }()
+
+ wg.Wait()
+}