Skip to content

Commit

Permalink
Remove TestSeekForward
Browse files Browse the repository at this point in the history
This test covers code paths that are highly dependent on time and
difficult to test deterministically. The core functionality
(ensuring that the delay is interrupted by seeking) is covered
by TestSeekForwardTwice, so combine those two test cases into one.
  • Loading branch information
zmb3 authored and github-actions committed Jun 18, 2024
1 parent c3f6e96 commit 0bd947d
Showing 1 changed file with 4 additions and 41 deletions.
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

0 comments on commit 0bd947d

Please sign in to comment.