Skip to content

Commit

Permalink
Merge pull request DFHack#5077 from dhthwy/jobid_monotonic_increase_test
Browse files Browse the repository at this point in the history
test that job ids increase monotonically
  • Loading branch information
myk002 authored Dec 4, 2024
2 parents aa47e09 + 4e4bea3 commit e1ae82d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/modules/job.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local utils = require('utils')

config.target = 'core'
config.mode = 'title' -- alters world state, not safe when a world is loaded

Expand All @@ -17,3 +19,28 @@ function test.removeJob()
expect.true_(dfhack.job.removeJob(job))
expect.nil_(df.global.world.jobs.list.next, 'job list is not empty after removeJob()')
end

-- EventManager job completion handling expects sorted order
function test.jobIDsAreSortedAfterAdd()
local job1 = df.job:new()
dfhack.job.linkIntoWorld(job1)

local job2 = df.job:new()
dfhack.job.linkIntoWorld(job2)

local is_sorted = true
local prev_id = nil

for _, job in utils.listpairs(df.global.world.jobs.list) do
if prev_id and job.id < prev_id then
is_sorted = false
break
end
prev_id = job.id
end

dfhack.job.removeJob(job1)
dfhack.job.removeJob(job2)

expect.true_(is_sorted)
end
22 changes: 22 additions & 0 deletions test/modules/job_fortress.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local utils = require('utils')

config.target = 'core'
config.mode = 'fortress'

-- EventManager job completion handling expects sorted order
function test.jobIDsAreSorted()
local is_sorted = true
local prev_id = nil

-- assumes there are at least some "naturally added" jobs currently in the list
-- but this should always be true for CI test saves
for _, job in utils.listpairs(df.global.world.jobs.list) do
if prev_id and job.id < prev_id then
is_sorted = false
break
end
prev_id = job.id
end

expect.true_(is_sorted)
end

0 comments on commit e1ae82d

Please sign in to comment.