-
Notifications
You must be signed in to change notification settings - Fork 205
ai/live: Fix race on publish close, advance trickle seq on empty writes #3824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "bytes" | ||
| "fmt" | ||
| "io" | ||
| "strconv" | ||
| "testing" | ||
| ) | ||
|
|
||
|
|
@@ -82,3 +83,46 @@ func TestLocalSubscriber_OverrunSeq(t *testing.T) { | |
| require.Nil(err) | ||
|
|
||
| } | ||
|
|
||
| func TestLocalSubscriber_PreconnectOnEmpty(t *testing.T) { | ||
| // Checks that the channel seq still increments even on zero-byte writes | ||
| require, url, server := makeServerWithServer(t) | ||
|
|
||
| pub, err := NewTricklePublisher(url) | ||
| require.Nil(err) | ||
| defer pub.Close() | ||
|
|
||
| sub := NewLocalSubscriber(server, "testest") | ||
| done := make(chan struct{}) | ||
|
|
||
| go func() { | ||
| defer close(done) | ||
| require.Nil(pub.Write(bytes.NewReader([]byte("hello")))) | ||
| require.Nil(pub.Close()) | ||
| }() | ||
|
|
||
| setSeqCount := 0 | ||
|
|
||
| for i := 0; ; i++ { | ||
| sub.SetSeq(-1) | ||
| td, err := sub.Read() | ||
| if err != nil { | ||
| break | ||
| } | ||
| require.Equal(strconv.Itoa(setSeqCount), td.Metadata["Lp-Trickle-Seq"]) | ||
|
|
||
| n, err := io.Copy(io.Discard, td.Reader) | ||
| require.Nil(err) | ||
| if i == 0 { | ||
| require.Equal(5, int(n)) // first write - "hello" | ||
| } else { | ||
| // second write latches on after first completes, but cancelled | ||
|
||
| // third write (preconnect after second) also cancelled | ||
| require.Equal(0, int(n)) | ||
| } | ||
| setSeqCount++ | ||
| } | ||
|
|
||
| <-done | ||
| require.Equal(2, setSeqCount) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a
require?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah it returns an error when the stream closes ... right now the error is kind of un-semantic ("stream not found" instead of "end of stream" until delayed teardowns are in), but added something in 4184452