Skip to content

Commit 5d44240

Browse files
committed
test(keys): assert add() return value instead of ngx.logs
Address review: KeyIndex:add() reports failures via its return value, so assert it directly instead of checking the global ngx.logs which can be stale/unrelated.
1 parent 57ec06c commit 5d44240

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

prometheus_test.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,8 @@ end
814814
-- bumped (other workers never re-synced) and list() iterated self.keys, so the
815815
-- same key was emitted twice -> duplicate metrics.
816816
function TestKeyIndex:testExpiredReAddNoDuplicate()
817-
self.key_index:add("expkey", "eviction_err", 1)
817+
local err = self.key_index:add("expkey", "eviction_err", 1)
818+
luaunit.assertEquals(err, nil)
818819
self.key_index:sync()
819820
luaunit.assertEquals(self.dict:get("_prefix_key_count"), 1)
820821
luaunit.assertEquals(self.dict:get("_prefix_key_1"), "expkey")
@@ -828,8 +829,8 @@ function TestKeyIndex:testExpiredReAddNoDuplicate()
828829
luaunit.assertEquals(self.dict:get("_prefix_key_1"), nil)
829830

830831
-- Re-adding the now-expired key takes the expired branch and allocates slot 2.
831-
self.key_index:add("expkey", "eviction_err", 1)
832-
luaunit.assertEquals(ngx.logs, nil)
832+
err = self.key_index:add("expkey", "eviction_err", 1)
833+
luaunit.assertEquals(err, nil)
833834
luaunit.assertEquals(self.dict:get("_prefix_key_2"), "expkey")
834835

835836
-- delete_count must have been bumped on the expired re-add path so that

0 commit comments

Comments
 (0)