Skip to content

Commit 0a554c6

Browse files
committed
update test
1 parent 66f3f1e commit 0a554c6

File tree

1 file changed

+6
-53
lines changed

1 file changed

+6
-53
lines changed

dbos/workflows_test.go

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,14 +1736,11 @@ func TestSendRecv(t *testing.T) {
17361736
})
17371737

17381738
t.Run("TestConcurrentRecvs", func(t *testing.T) {
1739-
// Test concurrent receivers - only 1 should timeout, others should get errors
1739+
// Test concurrent receivers - all should return valid results
17401740
receiveTopic := "concurrent-recv-topic"
17411741

1742-
// Start multiple concurrent receive workflows - no messages will be sent
1742+
// Start multiple concurrent receive workflows
17431743
numReceivers := 5
1744-
var wg sync.WaitGroup
1745-
results := make(chan string, numReceivers)
1746-
errors := make(chan error, numReceivers)
17471744
receiverHandles := make([]WorkflowHandle[string], numReceivers)
17481745

17491746
// Start all receivers - they will signal when ready and wait for coordination
@@ -1768,56 +1765,12 @@ func TestSendRecv(t *testing.T) {
17681765
// Now unblock all receivers simultaneously so they race to the Recv call
17691766
concurrentRecvStartEvent.Set()
17701767

1771-
// Collect results from all receivers concurrently
1772-
// Only 1 should timeout (winner of the CV), others should get errors
1773-
wg.Add(numReceivers)
1768+
// Collect results from all receivers
17741769
for i := range numReceivers {
1775-
go func(index int) {
1776-
defer wg.Done()
1777-
result, err := receiverHandles[index].GetResult()
1778-
if err != nil {
1779-
errors <- err
1780-
} else {
1781-
results <- result
1782-
}
1783-
}(i)
1784-
}
1785-
1786-
wg.Wait()
1787-
close(results)
1788-
close(errors)
1789-
1790-
// Count timeout results and errors
1791-
timeoutCount := 0
1792-
errorCount := 0
1793-
1794-
for result := range results {
1795-
if result == "" {
1796-
// Empty string indicates a timeout - only 1 receiver should get this
1797-
timeoutCount++
1798-
}
1770+
result, err := receiverHandles[i].GetResult()
1771+
require.NoError(t, err, "receiver %d should not error", i)
1772+
require.Equal(t, result, "", "receiver %d should have an empty string result", i)
17991773
}
1800-
1801-
for err := range errors {
1802-
t.Logf("Receiver error (expected): %v", err)
1803-
1804-
// Check that the error is of the expected type
1805-
dbosErr, ok := err.(*DBOSError)
1806-
require.True(t, ok, "expected error to be of type *DBOSError, got %T", err)
1807-
require.Equal(t, ConflictingIDError, dbosErr.Code, "expected error code to be ConflictingIDError, got %v", dbosErr.Code)
1808-
require.Equal(t, "concurrent-recv-wfid", dbosErr.WorkflowID, "expected workflow ID to be 'concurrent-recv-wfid', got %s", dbosErr.WorkflowID)
1809-
require.True(t, dbosErr.IsBase, "expected error to have IsBase=true")
1810-
require.Contains(t, dbosErr.Message, "Conflicting workflow ID concurrent-recv-wfid", "expected error message to contain conflicting workflow ID")
1811-
1812-
errorCount++
1813-
}
1814-
1815-
// Verify that exactly 1 receiver timed out and 4 got errors
1816-
assert.Equal(t, 1, timeoutCount, "expected exactly 1 receiver to timeout")
1817-
assert.Equal(t, 4, errorCount, "expected exactly 4 receivers to get errors")
1818-
1819-
// Ensure total results match expected
1820-
assert.Equal(t, numReceivers, timeoutCount+errorCount, "expected total results to equal number of receivers")
18211774
})
18221775

18231776
t.Run("durableSleep", func(t *testing.T) {

0 commit comments

Comments
 (0)