2021-01-15 11:53:22 +08:00
|
|
|
package proxy
|
2020-10-15 16:32:22 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-14 11:24:49 +08:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2020-11-03 14:53:36 +08:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-10-15 16:32:22 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-11-14 11:24:49 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/allocator"
|
2020-10-15 16:32:22 +08:00
|
|
|
)
|
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
var trueCnt = 0
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
func checkFunc(timestamp Timestamp) bool {
|
|
|
|
ret := rand.Intn(2) == 1
|
|
|
|
if ret {
|
|
|
|
trueCnt++
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeTick_Start(t *testing.T) {
|
|
|
|
fmt.Println("HHH")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeTick_Start2(t *testing.T) {
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-12-03 19:00:11 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
2020-11-21 15:06:46 +08:00
|
|
|
masterAddr := Params.MasterAddress()
|
2020-11-16 21:10:43 +08:00
|
|
|
tsoAllocator, err := allocator.NewTimestampAllocator(ctx, masterAddr)
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = tsoAllocator.Start()
|
2020-11-03 14:53:36 +08:00
|
|
|
assert.Nil(t, err)
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-21 19:12:59 +08:00
|
|
|
tt := newTimeTick(ctx, tsoAllocator, Params.TimeTickInterval(), checkFunc)
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
tsoAllocator.Close()
|
|
|
|
tt.Close()
|
|
|
|
}()
|
2020-10-15 16:32:22 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
tt.Start()
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2020-11-14 11:24:49 +08:00
|
|
|
<-ctx.Done()
|
2020-10-15 16:32:22 +08:00
|
|
|
|
|
|
|
}
|