From 0bd947d201b0f75069da08ccc7157f528cf448d0 Mon Sep 17 00:00:00 2001 From: Zac Bergquist Date: Wed, 12 Jun 2024 13:13:48 -0600 Subject: [PATCH] Remove TestSeekForward 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. --- lib/player/player_test.go | 45 ++++----------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/lib/player/player_test.go b/lib/player/player_test.go index 7194de39379d0..a64418df941f5 100644 --- a/lib/player/player_test.go +++ b/lib/player/player_test.go @@ -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, @@ -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