From 050cc03ae21bca2882094b61ed6fa1933fa7a1fb Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Fri, 1 May 2026 15:14:03 +1000 Subject: [PATCH] fix: daemon_test.go allocation --- spinifex/daemon/daemon_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spinifex/daemon/daemon_test.go b/spinifex/daemon/daemon_test.go index c3deba6b1..7d7e1d8ae 100644 --- a/spinifex/daemon/daemon_test.go +++ b/spinifex/daemon/daemon_test.go @@ -1655,9 +1655,13 @@ func TestResourceManager_ConcurrentAccess(t *testing.T) { // Goroutine 1: Allocate and deallocate go func() { for range iterations { + // canAllocate -> allocate is non-atomic; allocate re-checks under + // the write lock and may fail if another goroutine took the slot. + // Only deallocate when allocate actually succeeded. if rm.canAllocate(microType, 1) >= 1 { - rm.allocate(microType) - rm.deallocate(microType) + if err := rm.allocate(microType); err == nil { + rm.deallocate(microType) + } } } done <- true @@ -1675,8 +1679,9 @@ func TestResourceManager_ConcurrentAccess(t *testing.T) { go func() { for range iterations { if rm.canAllocate(microType, 1) >= 1 { - rm.allocate(microType) - rm.deallocate(microType) + if err := rm.allocate(microType); err == nil { + rm.deallocate(microType) + } } } done <- true