diff options
author | Valery Piashchynski <[email protected]> | 2020-12-03 13:42:47 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-03 13:42:47 +0300 |
commit | dbcd8647d878abff04636f77eed87243b3758abb (patch) | |
tree | dfad506dfa48b6bdf07a9b1e138a0628627a0e2d /sync_worker_test.go | |
parent | 1a2d525dfb5b8d1d59c93da79fabcf2ca3f5c56d (diff) |
Add mutex to protect string write in goroutine
Diffstat (limited to 'sync_worker_test.go')
-rwxr-xr-x | sync_worker_test.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/sync_worker_test.go b/sync_worker_test.go index b44efd2e..30b5bae8 100755 --- a/sync_worker_test.go +++ b/sync_worker_test.go @@ -4,6 +4,7 @@ import ( "context" "os/exec" "strings" + "sync" "testing" "time" @@ -162,9 +163,12 @@ func Test_Broken(t *testing.T) { } data := "" + mu := &sync.Mutex{} w.AddListener(func(event interface{}) { if wev, ok := event.(WorkerEvent); ok { + mu.Lock() data = string(wev.Payload.([]byte)) + mu.Unlock() } }) @@ -179,9 +183,11 @@ func Test_Broken(t *testing.T) { assert.Nil(t, res.Context) time.Sleep(time.Second * 3) + mu.Lock() if strings.ContainsAny(data, "undefined_function()") == false { t.Fail() } + mu.Unlock() assert.Error(t, w.Stop(ctx)) } |