From 25b10a18960ffc3d3e9255b2d5d6226c0a11ff2f Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Thu, 13 Nov 2025 15:25:50 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20test=20for=20WaitForError=20w?= =?UTF-8?q?hen=20firstErr=20is=20already=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- waiterr_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/waiterr_test.go b/waiterr_test.go index a2691be..6e663a3 100644 --- a/waiterr_test.go +++ b/waiterr_test.go @@ -103,3 +103,23 @@ func TestWaitForErrorPanic(t *testing.T) { we := new(waiterr.WaitErr) _ = we.WaitForError() } + +func TestWaitForErrorFirstErrSet(t *testing.T) { + we := new(waiterr.WaitErr) + expectedErr := errors.New("pre-set error") + + // Manually set firstErr (requires reflection or a way to access unexported fields) + // For testing purposes, we can simulate this by calling Go with an error first + we.Go(func() error { return expectedErr }) + we.Go(func() error { return errors.New("another error") }) + we.Go(func() error { return nil }) + + // Wait for a short period to ensure the first error is processed + // In a real scenario, this might be handled by a channel or more robust synchronization + // For this test, we'll rely on the Go routine scheduling to set firstErr quickly + _ = we.WaitForError() // Call once to ensure firstErr is set internally + + // Now call WaitForError again, expecting it to return the already set firstErr + actualErr := we.WaitForError() + be.Err(t, actualErr, expectedErr) +}