From 973c3108b71063ea932aed6c67e16e393b5e6c41 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 7 May 2026 00:03:30 +0300 Subject: task 81: replace test sleeps with deterministic sync --- internal/model/scan_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'internal/model') diff --git a/internal/model/scan_test.go b/internal/model/scan_test.go index cc0ba6b..acd1dd1 100644 --- a/internal/model/scan_test.go +++ b/internal/model/scan_test.go @@ -2,8 +2,8 @@ package model import ( "errors" + "sync" "testing" - "time" ) func TestScanProgress_Start(t *testing.T) { @@ -116,8 +116,11 @@ func TestScanProgress_ConcurrentAccess(t *testing.T) { p.Start(2) p.SetFilesTotal(100) + start := make(chan struct{}) done := make(chan struct{}) + var copies sync.WaitGroup go func() { + <-start for i := 0; i < 50; i++ { p.IncrementFile() } @@ -125,9 +128,15 @@ func TestScanProgress_ConcurrentAccess(t *testing.T) { }() for i := 0; i < 50; i++ { - _ = p.Copy() - time.Sleep(time.Microsecond) - } + copies.Add(1) + go func() { + defer copies.Done() + <-start + _ = p.Copy() + }() + } + close(start) + copies.Wait() <-done cp := p.Copy() -- cgit v1.2.3