Skip to content

Commit f84f6e0

Browse files
committed
test that job ids increase monotonically
1 parent 0ba92b4 commit f84f6e0

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

test/modules/job.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local utils = require('utils')
2+
13
config.target = 'core'
24
config.mode = 'title' -- alters world state, not safe when a world is loaded
35

@@ -17,3 +19,28 @@ function test.removeJob()
1719
expect.true_(dfhack.job.removeJob(job))
1820
expect.nil_(df.global.world.jobs.list.next, 'job list is not empty after removeJob()')
1921
end
22+
23+
-- EventManager job completion handling expects sorted order
24+
function test.jobIDsAreSortedAfterAdd()
25+
local job1 = df.job:new()
26+
dfhack.job.linkIntoWorld(job1)
27+
28+
local job2 = df.job:new()
29+
dfhack.job.linkIntoWorld(job2)
30+
31+
local is_sorted = true
32+
local prev_id = nil
33+
34+
for _, job in utils.listpairs(df.global.world.jobs.list) do
35+
if prev_id and job.id < prev_id then
36+
is_sorted = false
37+
break
38+
end
39+
prev_id = job.id
40+
end
41+
42+
dfhack.job.removeJob(job1)
43+
dfhack.job.removeJob(job2)
44+
45+
expect.true_(is_sorted)
46+
end

test/modules/job_fortress.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local utils = require('utils')
2+
3+
config.target = 'core'
4+
config.mode = 'fortress'
5+
6+
-- EventManager job completion handling expects sorted order
7+
function test.jobIDsAreSorted()
8+
local is_sorted = true
9+
local prev_id = nil
10+
11+
for _, job in utils.listpairs(df.global.world.jobs.list) do
12+
if prev_id and job.id < prev_id then
13+
is_sorted = false
14+
break
15+
end
16+
prev_id = job.id
17+
end
18+
19+
expect.true_(is_sorted)
20+
end

0 commit comments

Comments
 (0)