Skip to content

Commit

Permalink
add a ut
Browse files Browse the repository at this point in the history
  • Loading branch information
okJiang committed Oct 17, 2022
1 parent 5a6d69c commit b047955
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions dumpling/export/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package export

import (
"testing"
"time"

"github.com/stretchr/testify/require"
)
Expand All @@ -30,3 +31,22 @@ func TestGetParameters(t *testing.T) {
require.EqualValues(t, float64(30), mid.FinishedRows)
require.EqualValues(t, float64(40), mid.EstimateTotalRows)
}

func TestSpeedRecorder(t *testing.T) {
testCases := []struct {
spentTime int64
finished int64
expected int64
}{
{spentTime: 1, finished: 100, expected: 100},
{spentTime: 2, finished: 200, expected: 50},
// already finished, will return last speed
{spentTime: 3, finished: 200, expected: 50},
}
speedRecorder := NewSpeedRecorder()
for _, tc := range testCases {
time.Sleep(time.Duration(tc.spentTime) * time.Second)
recentSpeed := speedRecorder.GetSpeed(tc.finished)
require.Equal(t, tc.expected, recentSpeed)
}
}

0 comments on commit b047955

Please sign in to comment.