Skip to content

Commit 5649437

Browse files
authored
Merge pull request #387 from hookdeck/chore/unit-tests
chore(ci): add GitHub Actions workflow for running unit tests
2 parents fd69ba2 + 166ad80 commit 5649437

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

.github/workflows/unit-tests.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Unit Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v4
11+
12+
- name: Set up Go
13+
uses: actions/setup-go@v5
14+
with:
15+
go-version: '1.23.0'
16+
17+
- name: Run unit tests
18+
run: make test/unit

internal/deliverymq/messagehandler_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,18 +1224,28 @@ func TestMessageHandler_AlertMonitorError(t *testing.T) {
12241224
assert.Equal(t, models.DeliveryStatusSuccess, logPublisher.deliveries[0].Delivery.Status, "delivery status should be OK")
12251225

12261226
// Verify alert monitor was called but error was ignored
1227+
// Wait for the HandleAttempt call to be made
1228+
require.Eventually(t, func() bool {
1229+
for _, call := range alertMonitor.Calls {
1230+
if call.Method == "HandleAttempt" {
1231+
return true
1232+
}
1233+
}
1234+
return false
1235+
}, 200*time.Millisecond, 10*time.Millisecond, "timed out waiting for HandleAttempt call on alertMonitor")
12271236
alertMonitor.AssertCalled(t, "HandleAttempt", mock.Anything, mock.Anything)
12281237
}
12291238

12301239
// Helper function to assert alert monitor calls
12311240
func assertAlertMonitor(t *testing.T, m *mockAlertMonitor, success bool, destination *models.Destination, expectedData map[string]interface{}) {
12321241
t.Helper()
12331242

1234-
// Wait a bit for goroutines
1235-
time.Sleep(100 * time.Millisecond)
1243+
// Wait for the alert monitor to be called
1244+
require.Eventually(t, func() bool {
1245+
return len(m.Calls) > 0
1246+
}, 200*time.Millisecond, 10*time.Millisecond, "timed out waiting for alert monitor to be called")
12361247

1237-
calls := m.Calls
1238-
require.NotEmpty(t, calls, "alert monitor should be called")
1248+
calls := m.Calls // m.Calls is now guaranteed to be non-empty
12391249

12401250
lastCall := calls[len(calls)-1]
12411251
attempt := lastCall.Arguments[1].(alert.DeliveryAttempt)

0 commit comments

Comments
 (0)