Skip to content
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

[v16] Deflake TestSeekForward #43212

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 4 additions & 41 deletions lib/player/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,46 +173,6 @@ func TestClose(t *testing.T) {
}

func TestSeekForward(t *testing.T) {
clk := clockwork.NewFakeClock()

p, err := player.New(&player.Config{
Clock: clk,
SessionID: "test-session",
Streamer: &simpleStreamer{count: 10, delay: 1000},
})
require.NoError(t, err)
require.NoError(t, p.Play())

clk.BlockUntil(1) // player is now waiting to emit event 0

// advance playback until right before the last event
p.SetPos(9001 * time.Millisecond)
clk.BlockUntil(1)

// advance the clock to unblock the player
// (it should now spit out all but the last event in rapid succession)
clk.Advance(1001 * time.Millisecond)

ch := make(chan struct{})
go func() {
defer close(ch)
for evt := range p.C() {
t.Logf("got event %v (delay=%v)", evt.GetID(), evt.GetCode())
}
}()

clk.BlockUntil(1)
require.Equal(t, int64(9000), p.LastPlayed())

clk.Advance(999 * time.Millisecond)
select {
case <-ch:
case <-time.After(3 * time.Second):
require.FailNow(t, "player hasn't closed in time")
}
}

func TestSeekForwardTwice(t *testing.T) {
clk := clockwork.NewRealClock()
p, err := player.New(&player.Config{
Clock: clk,
Expand Down Expand Up @@ -323,7 +283,10 @@ func (s *simpleStreamer) StreamSessionEvents(ctx context.Context, sessionID sess
Type: events.SessionPrintEvent,
Index: i,
ID: strconv.Itoa(int(i)),
Code: strconv.FormatInt((i+1)*s.delay, 10),

// stuff the event delay in the code field so that it's easy
// to access without a type assertion
Code: strconv.FormatInt((i+1)*s.delay, 10),
},
Data: []byte(fmt.Sprintf("event %d\n", i)),
ChunkIndex: i, // TODO(zmb3) deprecate this
Expand Down
Loading