diff --git a/cmd_stream_test.go b/cmd_stream_test.go index 8ad6dd64..67cf66ed 100644 --- a/cmd_stream_test.go +++ b/cmd_stream_test.go @@ -1,6 +1,7 @@ package miniredis import ( + "context" "fmt" "math" "regexp" @@ -421,29 +422,36 @@ func TestStreamRead(t *testing.T) { t.Run("blocking async", func(t *testing.T) { // XREAD blocking test using latest ID + ctx, cancel := context.WithCancel(context.Background()) var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() - mustDo(t, c, - "XREAD", "BLOCK", "0", "STREAMS", "planets", "$", - proto.Array( - proto.Array(proto.String("planets"), - proto.Array( - proto.Array(proto.String("5-1"), proto.Strings("name", "block", "idx", "6")), - ), - ), - ), - ) + xaddClient, err := proto.Dial(s.Addr()) + ok(t, err) + defer xaddClient.Close() + for { + select { + case <-time.After(10 * time.Millisecond): + case <-ctx.Done(): + return + } + _, err = xaddClient.Do("XADD", "planets", "5-1", "name", "block", "idx", "6") + ok(t, err) + } }() - // Wait for the blocking XREAD to start and then run XADD - xaddClient, err := proto.Dial(s.Addr()) - ok(t, err) - defer xaddClient.Close() - - _, err = xaddClient.Do("XADD", "planets", "5-1", "name", "block", "idx", "6") - ok(t, err) + mustDo(t, c, + "XREAD", "BLOCK", "0", "STREAMS", "planets", "$", + proto.Array( + proto.Array(proto.String("planets"), + proto.Array( + proto.Array(proto.String("5-1"), proto.Strings("name", "block", "idx", "6")), + ), + ), + ), + ) + cancel() wg.Wait() }) }) diff --git a/go.mod b/go.mod index 8f0fa1ca..b32585f1 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/alicebob/miniredis/v2 require ( github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a - github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 + github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64 ) go 1.14 diff --git a/go.sum b/go.sum index b99d65a0..199f25c3 100644 --- a/go.sum +++ b/go.sum @@ -5,4 +5,6 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 h1:k/gmLsJDWwWqbLCur2yWnJzwQEKRcAHXo6seXGuSwWw= github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA= +github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64 h1:5mLPGnFdSsevFRFc9q3yYbBkB6tsm4aCwwQV/j1JQAQ= +github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=