From f84f6e0bacca5465d0b8a52a36e4473a6c88fdf0 Mon Sep 17 00:00:00 2001 From: dhthwy <302825+dhthwy@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:09:52 -0500 Subject: [PATCH 1/2] test that job ids increase monotonically --- test/modules/job.lua | 27 +++++++++++++++++++++++++++ test/modules/job_fortress.lua | 20 ++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/modules/job_fortress.lua diff --git a/test/modules/job.lua b/test/modules/job.lua index 518cb26a3a..6f7090e731 100644 --- a/test/modules/job.lua +++ b/test/modules/job.lua @@ -1,3 +1,5 @@ +local utils = require('utils') + config.target = 'core' config.mode = 'title' -- alters world state, not safe when a world is loaded @@ -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 diff --git a/test/modules/job_fortress.lua b/test/modules/job_fortress.lua new file mode 100644 index 0000000000..635b62da02 --- /dev/null +++ b/test/modules/job_fortress.lua @@ -0,0 +1,20 @@ +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 + + 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 From 4e4bea3f222808468cbcf8530632e81e0fdb0551 Mon Sep 17 00:00:00 2001 From: Myk Date: Wed, 4 Dec 2024 06:50:48 -0800 Subject: [PATCH 2/2] add clarifying comment for test --- test/modules/job_fortress.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/modules/job_fortress.lua b/test/modules/job_fortress.lua index 635b62da02..6f3047c8bf 100644 --- a/test/modules/job_fortress.lua +++ b/test/modules/job_fortress.lua @@ -8,6 +8,8 @@ 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