blob: 6a0f6ad338f24774d0aab579bce392e517149e70 [file] [log] [blame]
package polling_status
import (
"encoding/json"
"fmt"
"strconv"
"testing"
"time"
"go.skia.org/infra/go/testutils"
assert "github.com/stretchr/testify/require"
)
var urlMap = map[string][]byte{}
func TestPollingStatus(t *testing.T) {
testutils.SmallTest(t)
i := 0
tc := []int64{0, 10, -35}
duration := 100 * time.Millisecond
ps := NewPollingStatus(func() (interface{}, error) {
if i >= len(tc) {
return 0, fmt.Errorf("Reached the end of test data.")
}
return tc[i], nil
}, duration)
time.Sleep(2 * duration)
for j, v := range tc {
bytes, err := json.Marshal(ps)
assert.NoError(t, err)
assert.Equal(t, []byte(strconv.FormatInt(int64(v), 10)), bytes)
i = j + 1
time.Sleep(duration)
}
ps.Stop()
}