Skip to content

Commit

Permalink
add more tests to scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Oct 27, 2024
1 parent 9f28f49 commit 327aa03
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions notifier/scheduler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package notifier

import (
"errors"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -103,6 +104,47 @@ func TestThrottling(t *testing.T) {
So(notification, ShouldResemble, &expected2)
})

Convey("Test sendFail more that 0, and no throttling, but subscription doesn't exists, should send message in one minute", t, func() {
params2 := params
params2.ThrottledOld = false
params2.SendFail = 1
testErr := errors.New("subscription doesn't exist")

expected2 := expected
expected2.SendFail = 1
expected2.Timestamp = now.Add(time.Minute).Unix()
systemClock.EXPECT().NowUTC().Return(now).Times(1)
dataBase.EXPECT().GetTriggerThrottling(params2.Event.TriggerID).Return(now, now)
dataBase.EXPECT().GetSubscription(*params2.Event.SubscriptionID).Return(moira.SubscriptionData{}, testErr)

notification := scheduler.ScheduleNotification(params2, logger)
So(notification, ShouldResemble, &expected2)
})

Convey("Test sendFail more that 0, and no throttling, but the subscription schedule postpones the dispatch time, should send message in one minute", t, func() {
params2 := params
params2.ThrottledOld = false
params2.SendFail = 1

// 2015-09-02, 01:00:00 GMT+03:00
now := time.Unix(1441144800, 0)
testSubscription := subscription
testSubscription.ThrottlingEnabled = false
testSubscription.Schedule = schedule3

expected2 := expected
expected2.SendFail = 1
// 2015-09-02, 02:00:00 GMT+03:00
expected2.Timestamp = time.Unix(1441148400, 0).Unix()
expected2.CreatedAt = now.Unix()
systemClock.EXPECT().NowUTC().Return(now).Times(1)
dataBase.EXPECT().GetTriggerThrottling(params2.Event.TriggerID).Return(now, now)
dataBase.EXPECT().GetSubscription(*params2.Event.SubscriptionID).Return(testSubscription, nil)

notification := scheduler.ScheduleNotification(params2, logger)
So(notification, ShouldResemble, &expected2)
})

Convey("Test sendFail more than 0, and has throttling, should send message in one minute", t, func() {
params2 := params
params2.ThrottledOld = true
Expand Down

0 comments on commit 327aa03

Please sign in to comment.