Skip to content

Commit 919016a

Browse files
committed
fix unit tests
1 parent 42f5577 commit 919016a

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

apps/flowlord/taskmaster_test.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ func TestIsReady(t *testing.T) {
531531
}
532532

533533
func TestNotification_Tick(t *testing.T) {
534-
// tickIn is the full pre-tick state: frequencies, watermarks relative to a single
534+
// in is the full pre-tick state: frequencies, watermarks relative to a single
535535
// time.Now() at the start of the test function, and an optional row inserted before Tick.
536-
type tickIn struct {
536+
type in struct {
537537
MinFrequency time.Duration
538538
MaxFrequency time.Duration
539539
InitFrequency time.Duration
@@ -542,15 +542,15 @@ func TestNotification_Tick(t *testing.T) {
542542
LastRunFromNow time.Duration
543543
AddAlert *task.Task // if non-nil, insert this alert before Tick
544544
}
545-
type tickOut struct {
546-
Freq time.Duration
547-
AlertsSentInSummary int // total alert rows passed to sendSummary (len of each batch summed)
545+
type out struct {
546+
Freq time.Duration
547+
Alerted bool
548548
}
549549

550-
fn := func(in tickIn) (tickOut, error) {
550+
fn := func(in in) (out, error) {
551551
db := &sqlite.SQLite{LocalPath: ":memory:"}
552552
if err := db.Open(base_test_path+"workflow", nil); err != nil {
553-
return tickOut{}, err
553+
return out{}, err
554554
}
555555
defer db.Close()
556556

@@ -564,65 +564,67 @@ func TestNotification_Tick(t *testing.T) {
564564
n.lastAlertTime = now.Add(in.LastAlertFromNow)
565565
n.lastRun = now.Add(in.LastRunFromNow)
566566

567-
if err := db.AddAlert(*in.AddAlert, "err"); err != nil {
568-
return tickOut{}, err
567+
if in.AddAlert != nil {
568+
if err := db.AddAlert(*in.AddAlert, "err"); err != nil {
569+
return out{}, err
570+
}
569571
}
570572

571-
alertsSentInSummary := 0
573+
alerted := false
572574
sendSummary := func(alerts []sqlite.AlertRecord) error {
573-
alertsSentInSummary += len(alerts)
575+
alerted = true
574576
return nil
575577
}
576578

577579
n.Tick(db, sendSummary)
578-
return tickOut{Freq: n.GetAlertFrequency(), AlertsSentInSummary: alertsSentInSummary}, nil
580+
return out{n.GetAlertFrequency(), alerted}, nil
579581
}
580582

581-
cases := trial.Cases[tickIn, tickOut]{
583+
cases := trial.Cases[in, out]{
582584
"de-escalate halves when no new alerts": {
583-
Input: tickIn{
585+
Input: in{
584586
MinFrequency: 5 * time.Minute, MaxFrequency: 80 * time.Minute,
585587
InitFrequency: 20 * time.Minute,
586588
LastAlertFromNow: 0, LastRunFromNow: 0,
587589
AddAlert: nil,
588590
},
589-
Expected: tickOut{Freq: 10 * time.Minute},
591+
Expected: out{Freq: 10 * time.Minute},
590592
},
591593
"de-escalate floors at MinFrequency": {
592-
Input: tickIn{
594+
Input: in{
593595
MinFrequency: 5 * time.Minute, MaxFrequency: 80 * time.Minute,
594596
InitFrequency: 8 * time.Minute,
595597
LastAlertFromNow: 0, LastRunFromNow: 0,
596598
AddAlert: nil,
597599
},
598-
Expected: tickOut{Freq: 5 * time.Minute},
600+
Expected: out{Freq: 5 * time.Minute},
599601
},
600602
"escalate doubles when new alerts since lastRun": {
601-
Input: tickIn{
603+
Input: in{
602604
MinFrequency: 5 * time.Minute, MaxFrequency: 80 * time.Minute,
603605
InitFrequency: 5 * time.Minute,
604606
LastAlertFromNow: 0, LastRunFromNow: -10 * time.Minute,
605607
AddAlert: &task.Task{ID: "esc", Type: "t1", Job: "j1"},
606608
},
607-
Expected: tickOut{Freq: 10 * time.Minute},
609+
Expected: out{Freq: 10 * time.Minute},
608610
},
609611
"summary send then escalate from new rows": {
610-
Input: tickIn{
612+
Input: in{
611613
MinFrequency: 5 * time.Minute, MaxFrequency: 80 * time.Minute,
612614
InitFrequency: 5 * time.Minute,
613615
LastAlertFromNow: -1 * time.Hour, LastRunFromNow: -15 * time.Minute,
614616
AddAlert: &task.Task{ID: "sum", Type: "t2", Job: "j2"},
615617
},
616-
Expected: tickOut{Freq: 10 * time.Minute, AlertsSentInSummary: 1},
618+
Expected: out{Freq: 10 * time.Minute, Alerted: true},
617619
},
618620
"at MaxFrequency new alerts do not raise further": {
619-
Input: tickIn{
621+
Input: in{
620622
MinFrequency: 5 * time.Minute, MaxFrequency: 80 * time.Minute,
621623
InitFrequency: 80 * time.Minute,
622624
LastAlertFromNow: 0, LastRunFromNow: -10 * time.Minute,
623625
AddAlert: &task.Task{ID: "max", Type: "t3", Job: "j3"},
624626
},
625-
Expected: tickOut{Freq: 80 * time.Minute},
627+
Expected: out{Freq: 80 * time.Minute},
626628
},
627629
}
628630

0 commit comments

Comments
 (0)