Skip to content

Commit

Permalink
fix(test): reset clock
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyong Huang <[email protected]>
  • Loading branch information
ngjaying committed Mar 29, 2024
1 parent 06b618e commit 4986d43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions internal/io/memory/lookupsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (
"time"

"github.com/benbjohnson/clock"
"github.com/stretchr/testify/assert"

"github.com/lf-edge/ekuiper/internal/conf"
"github.com/lf-edge/ekuiper/internal/io/memory/pubsub"
"github.com/lf-edge/ekuiper/internal/topo/context"
"github.com/lf-edge/ekuiper/internal/topo/topotest/mockclock"
"github.com/lf-edge/ekuiper/pkg/api"
)

Expand Down Expand Up @@ -117,21 +119,23 @@ func TestLookup(t *testing.T) {
}
}
}()
mc := conf.Clock.(*clock.Mock)
result, _ := ls.Lookup(ctx, []string{}, []string{"ff"}, []interface{}{"value1"})
mockclock.ResetClock(0)
mc := mockclock.GetMockClock()
expected := []api.SourceTuple{
api.NewDefaultSourceTupleWithTime(map[string]interface{}{"ff": "value1", "gg": "value2"}, map[string]interface{}{"topic": "test2"}, mc.Now()),
api.NewDefaultSourceTupleWithTime(map[string]interface{}{"ff": "value1", "gg": "value4"}, map[string]interface{}{"topic": "test2"}, mc.Now()),
}
result, _ := ls.Lookup(ctx, []string{}, []string{"ff"}, []interface{}{"value1"})
if len(result) != 2 {
t.Errorf("expect %v but got %v", expected, result)
} else {
if result[0].Message()["gg"] != "value2" {
result[0], result[1] = result[1], result[0]
}
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("expect %v but got %v", expected, result)
assert.Equal(t, len(expected), len(result))
for i, r := range result {
assert.Equal(t, expected[i].Message(), r.Message(), "%d message not equal", i)
}
err = ls.Close(ctx)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/topo/node/lookup_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/lf-edge/ekuiper/internal/plugin"
"github.com/lf-edge/ekuiper/internal/topo/context"
"github.com/lf-edge/ekuiper/internal/topo/lookup"
"github.com/lf-edge/ekuiper/internal/topo/topotest/mockclock"
"github.com/lf-edge/ekuiper/internal/xsql"
"github.com/lf-edge/ekuiper/pkg/api"
"github.com/lf-edge/ekuiper/pkg/ast"
Expand Down Expand Up @@ -318,6 +319,7 @@ func TestLookup(t *testing.T) {
STRICT_VALIDATION: true,
KIND: "lookup",
}
mockclock.ResetClock(0)
lookup.CreateInstance("mock", "mock", options)
contextLogger := conf.Log.WithField("rule", "TestLookup")
ctx := context.WithValue(context.Background(), context.LoggerKey, contextLogger)
Expand Down Expand Up @@ -468,7 +470,8 @@ func TestCachedLookup(t *testing.T) {
},
}
// First run and the set mock result
clock := conf.Clock.(*clock.Mock)
mockclock.ResetClock(0)
clock := mockclock.GetMockClock()
select {
case err := <-errCh:
t.Error(err)
Expand Down

0 comments on commit 4986d43

Please sign in to comment.