Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions internal/pkg/platform/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package platform

import (
"context"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -212,17 +213,19 @@ func TestPlatformActivity_StreamingLogs(t *testing.T) {
PollingIntervalMS: 20, // poll activity every 20 ms
},
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) context.Context {
cm.API.On("Activity", mock.Anything, mock.Anything, mock.Anything).Return(api.ActivityResult{}, nil)
var calls atomic.Int32
ctx, cancel := context.WithCancel(ctx)
go func() {
time.Sleep(time.Millisecond * 50) // cancel activity in 50 ms
cancel()
}()
cm.API.On("Activity", mock.Anything, mock.Anything, mock.Anything).
Run(func(args mock.Arguments) {
if calls.Add(1) >= 2 {
cancel()
}
}).
Return(api.ActivityResult{}, nil)
return ctx
},
ExpectedError: nil,
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
// with the above polling/canceling setup, expectation is activity called two times.
cm.API.AssertNumberOfCalls(t, "Activity", 2)
},
},
Expand All @@ -232,17 +235,16 @@ func TestPlatformActivity_StreamingLogs(t *testing.T) {
PollingIntervalMS: 20, // poll activity every 20 ms
},
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) context.Context {
cm.API.On("Activity", mock.Anything, mock.Anything, mock.Anything).Return(api.ActivityResult{}, nil)
ctx, cancel := context.WithCancel(ctx)
go func() {
time.Sleep(time.Millisecond * 10) // cancel activity in 10 ms
cancel()
}()
cm.API.On("Activity", mock.Anything, mock.Anything, mock.Anything).
Run(func(args mock.Arguments) {
cancel()
}).
Return(api.ActivityResult{}, nil)
return ctx
},
ExpectedError: nil,
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
// with the above polling/canceling setup, expectation is activity called only once.
cm.API.AssertNumberOfCalls(t, "Activity", 1)
},
},
Expand All @@ -253,17 +255,19 @@ func TestPlatformActivity_StreamingLogs(t *testing.T) {
PollingIntervalMS: 20, // poll activity every 20 ms
},
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) context.Context {
cm.API.On("Activity", mock.Anything, mock.Anything, mock.Anything).Return(api.ActivityResult{}, slackerror.New("mock_broken_logs"))
var calls atomic.Int32
ctx, cancel := context.WithCancel(ctx)
go func() {
time.Sleep(time.Millisecond * 50) // cancel activity in 50 ms
cancel()
}()
cm.API.On("Activity", mock.Anything, mock.Anything, mock.Anything).
Run(func(args mock.Arguments) {
if calls.Add(1) >= 3 {
cancel()
}
}).
Return(api.ActivityResult{}, slackerror.New("mock_broken_logs"))
return ctx
},
ExpectedError: nil,
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
// with the above polling/canceling setup, expectation is activity called three times.
cm.API.AssertNumberOfCalls(t, "Activity", 3)
},
},
Expand Down
Loading