Skip to content

Commit

Permalink
chore: fix flapping TFunctionList test.
Browse files Browse the repository at this point in the history
Fixes the Redis Gears TFunctionList test, which was flapping due to
an undefined order of functions being returned.
  • Loading branch information
Michael Kuc committed Aug 22, 2023
1 parent 52f0ac0 commit 6b9b833
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions redis_gears_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func libCodeWithConfig(libName string) string {
lib := `#!js api_version=1.0 name=%s
var last_update_field_name = "__last_update__"
if (redis.config.last_update_field_name !== undefined) {
if (typeof redis.config.last_update_field_name != 'string') {
throw "last_update_field_name must be a string";
}
last_update_field_name = redis.config.last_update_field_name
}
redis.registerFunction("hset", function(client, key, field, val){
// get the current time in ms
var curr_time = client.call("time")[0];
Expand All @@ -47,7 +47,6 @@ var _ = Describe("RedisGears commands", Label("gears"), func() {
})

It("should TFunctionLoad, TFunctionLoadArgs and TFunctionDelete ", Label("gears", "tfunctionload"), func() {

resultAdd, err := client.TFunctionLoad(ctx, libCode("libtflo1")).Result()
Expect(err).NotTo(HaveOccurred())
Expect(resultAdd).To(BeEquivalentTo("OK"))
Expand All @@ -60,6 +59,7 @@ var _ = Describe("RedisGears commands", Label("gears"), func() {
Expect(resultAdd).To(BeEquivalentTo("OK"))

})

It("should TFunctionList", Label("gears", "tfunctionlist"), func() {
resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfli1")).Result()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -73,7 +73,13 @@ var _ = Describe("RedisGears commands", Label("gears"), func() {
opt := &redis.TFunctionListOptions{Withcode: true, Verbose: 2}
resultListArgs, err := client.TFunctionListArgs(ctx, opt).Result()
Expect(err).NotTo(HaveOccurred())
Expect(resultListArgs[0]["code"]).To(BeEquivalentTo(libCode("libtfli1")))

resultFunctionCodes := make([]string, len(resultListArgs))
for i, function := range resultListArgs {
resultFunctionCodes[i] = function["code"].(string)
}

Expect(resultFunctionCodes).To(ConsistOf(libCode("libtfli1"), libCode("libtfli2")))
resultAdd, err = client.TFunctionDelete(ctx, "libtfli1").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resultAdd).To(BeEquivalentTo("OK"))
Expand Down Expand Up @@ -135,5 +141,4 @@ var _ = Describe("RedisGears commands", Label("gears"), func() {
Expect(err).NotTo(HaveOccurred())
Expect(resultAdd).To(BeEquivalentTo("OK"))
})

})

0 comments on commit 6b9b833

Please sign in to comment.