Skip to content

Commit 0e751f1

Browse files
committed
test: fix flaky testcases
Seralization to JSON is not deterministic, so the order of keys in a table is not defined. The patch fixes test checks for `to:json()` method.
1 parent 2ee8b4f commit 0e751f1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

test/tests.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test:test('clock', function(test)
4444
end)
4545

4646
test:test('history', function(test)
47-
test:plan(9)
47+
test:plan(12)
4848
test:isnt(history.new(), nil, "history.new()")
4949

5050
local h = history.new()
@@ -72,18 +72,21 @@ test:test('history', function(test)
7272

7373
h = history.new()
7474
h:add({ type = 'ok', value = 2 })
75-
local ref_str = '[{"type":"ok","value":2}]'
76-
test:is(h:to_json(), ref_str, "history_obj:to_json(): { type = 'ok' }")
75+
local history_json = h:to_json()
76+
test:like(history_json, '"value":2')
77+
test:like(history_json, '"type":"ok"')
7778

7879
h = history.new()
7980
h:add({ type = 'fail', value = 3 })
80-
ref_str = '[{"type":"fail","value":3}]'
81-
test:is(h:to_json(), ref_str, "history_obj:to_json(): { type = 'fail' }")
81+
history_json = h:to_json()
82+
test:like(history_json, '"value":3')
83+
test:like(history_json, '"type":"fail"')
8284

8385
h = history.new()
8486
h:add({ type = 'invoke', value = 6 })
85-
ref_str = '[{"type":"invoke","value":6}]'
86-
test:is(h:to_json(), ref_str, "history_obj:to_json(): { type = 'invoke' }")
87+
history_json = h:to_json()
88+
test:like(history_json, '"value":6')
89+
test:like(history_json, '"type":"invoke"')
8790
end)
8891

8992
test:test('op', function(test)

0 commit comments

Comments
 (0)