summaryrefslogtreecommitdiffstats
path: root/pkg/tasks/async_handler_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tasks/async_handler_test.go')
-rw-r--r--pkg/tasks/async_handler_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkg/tasks/async_handler_test.go b/pkg/tasks/async_handler_test.go
new file mode 100644
index 000000000..b6edbec20
--- /dev/null
+++ b/pkg/tasks/async_handler_test.go
@@ -0,0 +1,44 @@
+package tasks
+
+import (
+ "fmt"
+ "sync"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAsyncHandler(t *testing.T) {
+ wg := sync.WaitGroup{}
+ wg.Add(2)
+
+ handler := NewAsyncHandler()
+ handler.onReject = func() {
+ wg.Done()
+ }
+
+ result := 0
+
+ wg2 := sync.WaitGroup{}
+ wg2.Add(1)
+
+ handler.Do(func() func() {
+ wg2.Wait()
+ return func() {
+ fmt.Println("setting to 1")
+ result = 1
+ }
+ })
+ handler.Do(func() func() {
+ return func() {
+ fmt.Println("setting to 2")
+ result = 2
+ wg.Done()
+ wg2.Done()
+ }
+ })
+
+ wg.Wait()
+
+ assert.EqualValues(t, 2, result)
+}