@@ -431,43 +431,46 @@ func TestGracefulStop(t *testing.T) {
431431 replay := NewReplay (zap .NewNop (), id .NewIDManager ())
432432 defer replay .Close ()
433433
434- i := 0
435- loader := & customizedReader {
436- getCmd : func () * cmd.Command {
437- j := rand .Uint64N (100 ) + 1
438- command := newMockCommand (j )
439- i ++
440- command .StartTs = time .Unix (0 , int64 (i )* int64 (time .Microsecond ))
441- return command
442- },
443- }
434+ // Test 2 rounds to test that the graceful flag will be reset before each round.
435+ for n := 0 ; n < 2 ; n ++ {
436+ i := 0
437+ loader := & customizedReader {
438+ getCmd : func () * cmd.Command {
439+ j := rand .Uint64N (100 ) + 1
440+ command := newMockCommand (j )
441+ i ++
442+ command .StartTs = time .Unix (0 , int64 (i )* int64 (time .Microsecond ))
443+ return command
444+ },
445+ }
444446
445- cfg := ReplayConfig {
446- Input : t .TempDir (),
447- Username : "u1" ,
448- StartTime : time .Now (),
449- readers : []cmd.LineReader {loader },
450- connCreator : func (connID uint64 , _ uint64 ) conn.Conn {
451- return & mockDelayConn {
452- stats : & replay .replayStats ,
453- closeCh : replay .closeConnCh ,
454- connID : connID ,
455- }
456- },
457- report : newMockReport (replay .exceptionCh ),
458- PSCloseStrategy : cmd .PSCloseStrategyDirected ,
459- }
460- require .NoError (t , replay .Start (cfg , nil , nil , & backend.BCConfig {}))
447+ cfg := ReplayConfig {
448+ Input : t .TempDir (),
449+ Username : "u1" ,
450+ StartTime : time .Now (),
451+ readers : []cmd.LineReader {loader },
452+ connCreator : func (connID uint64 , _ uint64 ) conn.Conn {
453+ return & mockDelayConn {
454+ stats : & replay .replayStats ,
455+ closeCh : replay .closeConnCh ,
456+ connID : connID ,
457+ }
458+ },
459+ report : newMockReport (replay .exceptionCh ),
460+ PSCloseStrategy : cmd .PSCloseStrategyDirected ,
461+ }
462+ require .NoError (t , replay .Start (cfg , nil , nil , & backend.BCConfig {}))
461463
462- time .Sleep (2 * time .Second )
463- replay .Stop (errors .New ("graceful stop" ), true )
464- // check that all the pending commands are replayed
465- curCmdTs := replay .replayStats .CurCmdTs .Load ()
466- require .EqualValues (t , 0 , replay .replayStats .PendingCmds .Load ())
467- require .EqualValues (t , curCmdTs , int64 (replay .replayStats .ReplayedCmds .Load ())* int64 (time .Microsecond ))
468- _ , _ , lastTs , _ , _ , err := replay .Progress ()
469- require .ErrorContains (t , err , "graceful stop" )
470- require .Equal (t , curCmdTs , lastTs .UnixNano ())
464+ time .Sleep (2 * time .Second )
465+ replay .Stop (errors .New ("graceful stop" ), true )
466+ // check that all the pending commands are replayed
467+ curCmdTs := replay .replayStats .CurCmdTs .Load ()
468+ require .EqualValues (t , 0 , replay .replayStats .PendingCmds .Load ())
469+ require .EqualValues (t , curCmdTs , int64 (replay .replayStats .ReplayedCmds .Load ())* int64 (time .Microsecond ))
470+ _ , _ , lastTs , _ , _ , err := replay .Progress ()
471+ require .ErrorContains (t , err , "graceful stop" )
472+ require .Equal (t , curCmdTs , lastTs .UnixNano ())
473+ }
471474}
472475
473476func BenchmarkMultiBufferedDecoder (b * testing.B ) {
0 commit comments