-
Notifications
You must be signed in to change notification settings - Fork 25
/
tasks_test.go
804 lines (712 loc) · 19.5 KB
/
tasks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
package tasks
import (
"context"
"fmt"
"sync"
"testing"
"time"
"github.com/rs/xid"
)
type InterfaceTestCase struct {
name string
task *Task
id string
addErr bool
}
type ExecutionTestCase struct {
name string
id string
ctx context.Context
cancel context.CancelFunc
task *Task
callsFunc bool
}
type Counter struct {
sync.RWMutex
val int
}
func NewCounter() *Counter {
return &Counter{}
}
func (c *Counter) Inc() {
c.Lock()
defer c.Unlock()
c.val++
}
func (c *Counter) Dec() {
c.Lock()
defer c.Unlock()
c.val--
}
func (c *Counter) Val() int {
c.RLock()
defer c.RUnlock()
return c.val
}
func TestTasksInterface(t *testing.T) {
var tt []InterfaceTestCase
tt = append(tt, InterfaceTestCase{
name: "Basic Valid Task",
task: &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return nil },
},
})
tt = append(tt, InterfaceTestCase{
name: "Basic Valid Task with ID",
task: &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return nil },
},
id: xid.New().String(),
})
tt = append(tt, InterfaceTestCase{
name: "Valid Task with ErrFunc",
task: &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return nil },
ErrFunc: func(_ error) {},
},
})
tt = append(tt, InterfaceTestCase{
name: "Valid Task with Context",
task: &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return nil },
ErrFunc: func(_ error) {},
TaskContext: TaskContext{Context: context.Background()},
},
})
tt = append(tt, InterfaceTestCase{
name: "Valid Task with Context and WithContextFuncs",
task: &Task{
Interval: time.Duration(1 * time.Second),
FuncWithTaskContext: func(_ TaskContext) error { return nil },
ErrFuncWithTaskContext: func(_ TaskContext, _ error) {},
TaskContext: TaskContext{Context: context.Background()},
},
})
tt = append(tt, InterfaceTestCase{
name: "Valid Task without Context but WithContextFuncs",
task: &Task{
Interval: time.Duration(1 * time.Second),
FuncWithTaskContext: func(_ TaskContext) error { return nil },
ErrFuncWithTaskContext: func(_ TaskContext, _ error) {},
},
})
tt = append(tt, InterfaceTestCase{
name: "Valid Task with StartAfter",
task: &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return nil },
StartAfter: time.Now().Add(time.Duration(1 * time.Second)),
},
})
tt = append(tt, InterfaceTestCase{
name: "Valid Task with StartAfter but in the past",
task: &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return nil },
StartAfter: time.Now().Add(time.Duration(-1 * time.Minute)),
},
})
tt = append(tt, InterfaceTestCase{
name: "Valid Task with RunOnce",
task: &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return nil },
RunOnce: true,
},
})
tt = append(tt, InterfaceTestCase{
name: "No Interval",
task: &Task{
TaskFunc: func() error { return nil },
},
addErr: true,
})
tt = append(tt, InterfaceTestCase{
name: "No TaskFunc or FuncWithTaskContext",
task: &Task{
Interval: time.Duration(1 * time.Second),
},
addErr: true,
})
// Create a base scheduler to use
scheduler := New()
defer scheduler.Stop()
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
var err error
id := tc.id
// Schedule the task
if tc.id != "" {
err = scheduler.AddWithID(tc.id, tc.task)
} else {
id, err = scheduler.Add(tc.task)
}
if err != nil && !tc.addErr {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
if err == nil && tc.addErr {
t.Errorf("Expected errors when scheduling an invalid task")
}
defer scheduler.Del(id)
if tc.id != "" {
t.Run(tc.name+" - Duplicate Task", func(t *testing.T) {
// Schedule the task
err := scheduler.AddWithID(tc.id, tc.task)
if err != ErrIDInUse {
t.Errorf("Expected errors when scheduling a duplicate task")
}
})
}
t.Run(tc.name+" - Lookup", func(t *testing.T) {
// Verify if task exists
_, err = scheduler.Lookup(id)
if err != nil && !tc.addErr {
t.Errorf("Unable to find newly scheduled task with Lookup - %s", err)
}
if err == nil && tc.addErr {
t.Errorf("Found task that should not exist - %s", id)
}
})
t.Run(tc.name+" - Task List", func(t *testing.T) {
// Check Task Map
tasks := scheduler.Tasks()
if len(tasks) != 1 && !tc.addErr {
t.Errorf("Unable to find newly scheduled task with Tasks")
}
if len(tasks) > 0 && tc.addErr {
t.Errorf("Found task that should not exist - %s", id)
}
})
// Reset for the next test
scheduler.Del(id)
})
}
}
func TestTaskExecution(t *testing.T) {
// Create a base scheduler to use
scheduler := New()
defer scheduler.Stop()
// Setup table tests
var tt []ExecutionTestCase
// Define a basic task
tc := ExecutionTestCase{
name: "Valid Task",
callsFunc: true,
}
tc.ctx, tc.cancel = context.WithCancel(context.Background())
tc.task = &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return fmt.Errorf("fake error") },
ErrFunc: func(e error) {
if e != nil {
tc.cancel()
}
},
}
tt = append(tt, tc)
// Define a task with TaskContext
tc2 := ExecutionTestCase{
name: "Valid Task with TaskContext",
callsFunc: true,
}
tc2.ctx, tc2.cancel = context.WithCancel(context.Background())
tc2.task = &Task{
Interval: time.Duration(1 * time.Second),
TaskContext: TaskContext{Context: tc2.ctx},
FuncWithTaskContext: func(taskCtx TaskContext) error {
if taskCtx.Context != tc2.ctx {
t.Logf("TaskContext.Context does not match expected context")
// return with no error to trigger a timeout failure
return nil
}
return fmt.Errorf("fake error")
},
ErrFuncWithTaskContext: func(taskCtx TaskContext, e error) {
if taskCtx == tc2.task.TaskContext && e != nil {
tc2.cancel()
}
if taskCtx.Context.Err() != context.Canceled {
t.Errorf("TaskContext.Context should be canceled")
}
},
}
tt = append(tt, tc2)
// Define a task then cancel it
tc3 := ExecutionTestCase{
name: "Cancel a Task before it's called",
}
tc3.ctx, tc3.cancel = context.WithCancel(context.Background())
tc3.task = &Task{
Interval: time.Duration(1 * time.Second),
StartAfter: time.Now().Add(time.Duration(5 * time.Second)),
TaskContext: TaskContext{Context: tc3.ctx},
TaskFunc: func() error {
tc.cancel()
return nil
},
}
tt = append(tt, tc3)
// Only call ErrFunc if error
tc4 := ExecutionTestCase{
name: "Only call ErrFunc if error",
callsFunc: true,
}
tc4.ctx, tc4.cancel = context.WithCancel(context.Background())
tc4.task = &Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error {
tc4.cancel()
return nil
},
ErrFunc: func(error) {
t.Errorf("ErrFunc should not be called")
},
}
tt = append(tt, tc4)
// Only call ErrFuncWithTaskContext if error
tc5 := ExecutionTestCase{
name: "Only call ErrFuncWithTaskContext if error",
callsFunc: true,
}
tc5.ctx, tc5.cancel = context.WithCancel(context.Background())
tc5.task = &Task{
Interval: time.Duration(1 * time.Second),
TaskContext: TaskContext{Context: tc5.ctx},
FuncWithTaskContext: func(_ TaskContext) error {
tc5.cancel()
return nil
},
ErrFuncWithTaskContext: func(_ TaskContext, _ error) {
t.Errorf("ErrFuncWithTaskContext should not be called")
},
}
tt = append(tt, tc5)
// Validate TaskContext ID
tc6 := ExecutionTestCase{
name: "Validate TaskContext ID",
callsFunc: true,
id: "test-id",
}
tc6.ctx, tc6.cancel = context.WithCancel(context.Background())
tc6.task = &Task{
Interval: time.Duration(1 * time.Second),
TaskContext: TaskContext{Context: tc6.ctx},
FuncWithTaskContext: func(taskCtx TaskContext) error {
if taskCtx.ID() != tc6.id {
t.Errorf("TaskContext.ID does not match expected ID")
}
tc6.cancel()
return nil
},
}
tt = append(tt, tc6)
// Verify that StartAfter time is respected
tc7 := ExecutionTestCase{
name: "Verify StartAfter time is respected",
callsFunc: true,
}
tc7StartAfter := time.Now().Add(time.Duration(5 * time.Second))
tc7.ctx, tc7.cancel = context.WithCancel(context.Background())
tc7.task = &Task{
Interval: time.Duration(1 * time.Second),
StartAfter: tc7StartAfter,
TaskContext: TaskContext{Context: tc7.ctx},
FuncWithTaskContext: func(_ TaskContext) error {
if time.Now().Before(tc7StartAfter) {
t.Errorf("Task should not have been called before StartAfter time")
return nil
}
tc7.cancel()
return nil
},
}
tt = append(tt, tc7)
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
var err error
id := tc.id
if tc.id != "" {
err = scheduler.AddWithID(tc.id, tc.task)
} else {
id, err = scheduler.Add(tc.task)
}
if err != nil {
t.Errorf("Unexpected errors when scheduling a task - %s", err)
}
// Cancel the task if it's not supposed to be called
if !tc.callsFunc {
scheduler.Del(id)
}
select {
case <-tc.ctx.Done():
if tc.callsFunc {
return
}
t.Errorf("Task was executed when it should not have been")
case <-time.After(time.Duration(10 * time.Second)):
if !tc.callsFunc {
return
}
t.Errorf("Task did not execute within 10 seconds")
}
})
}
}
func TestAdd(t *testing.T) {
// Create a base scheduler to use
scheduler := New()
defer scheduler.Stop()
t.Run("Add a valid task and look it up", func(t *testing.T) {
id, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Minute),
TaskFunc: func() error { return nil },
ErrFunc: func(_ error) {},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
_, err = scheduler.Lookup(id)
if err != nil {
t.Errorf("Unable to find newly scheduled task with Lookup - %s", err)
}
tt := scheduler.Tasks()
if len(tt) < 1 {
t.Errorf("Unable to find newly scheduled task with Tasks")
}
})
t.Run("Add a valid task with an id and look it up", func(t *testing.T) {
id := xid.New()
err := scheduler.AddWithID(id.String(), &Task{
Interval: time.Duration(1 * time.Minute),
TaskFunc: func() error { return nil },
ErrFunc: func(_ error) {},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
_, err = scheduler.Lookup(id.String())
if err != nil {
t.Errorf("Unable to find newly scheduled task with Lookup - %s", err)
}
tt := scheduler.Tasks()
if len(tt) < 1 {
t.Errorf("Unable to find newly scheduled task with Tasks")
}
})
t.Run("Add a invalid task with an duplicate id and look it up", func(t *testing.T) {
// Channel for orchestrating when the task ran
doneCh := make(chan struct{})
// Setup A task
id, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error {
doneCh <- struct{}{}
return nil
},
ErrFunc: func(_ error) {},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
err = scheduler.AddWithID(id, &Task{
Interval: time.Duration(1 * time.Minute),
TaskFunc: func() error { return nil },
ErrFunc: func(_ error) {},
})
if err != ErrIDInUse {
t.Errorf("Expected error for task with existing id")
}
_, err = scheduler.Lookup(id)
if err != nil {
t.Errorf("Unable to find previously scheduled task with Lookup - %s", err)
}
})
t.Run("Check for nil callback", func(t *testing.T) {
_, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Minute),
ErrFunc: func(_ error) {},
})
if err == nil {
t.Errorf("Unexpected success when scheduling an invalid task - %s", err)
}
})
t.Run("Check for nil interval", func(t *testing.T) {
_, err := scheduler.Add(&Task{
TaskFunc: func() error { return nil },
ErrFunc: func(_ error) {},
})
if err == nil {
t.Errorf("Unexpected success when scheduling an invalid task - %s", err)
}
})
}
func TestScheduler(t *testing.T) {
// Create a base scheduler to use
scheduler := New()
defer scheduler.Stop()
t.Run("Verify Tasks Run when Added", func(t *testing.T) {
// Channel for orchestrating when the task ran
doneCh := make(chan struct{})
// Setup A task
id, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error {
doneCh <- struct{}{}
return nil
},
ErrFunc: func(_ error) {},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
defer scheduler.Del(id)
// Make sure it runs especially when we want it too
for i := 0; i < 6; i++ {
select {
case <-doneCh:
continue
case <-time.After(2 * time.Second):
t.Errorf("Scheduler failed to execute the scheduled tasks %d run within 2 seconds", i)
}
}
})
t.Run("Verify TasksWithContext Run when Added", func(t *testing.T) {
// Channel for orchestrating when the task ran
doneCh := make(chan struct{})
// User-defined context
ctx, cancel := context.WithCancel(context.Background())
// Setup A task
id, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Second),
TaskContext: TaskContext{Context: ctx},
FuncWithTaskContext: func(_ TaskContext) error {
cancel()
return fmt.Errorf("Fake Error")
},
ErrFuncWithTaskContext: func(ctx TaskContext, _ error) {
if ctx.Context != nil && ctx.Context.Err() == context.Canceled {
doneCh <- struct{}{}
}
},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
defer scheduler.Del(id)
// Make sure it runs especially when we want it too
for i := 0; i < 6; i++ {
select {
case <-doneCh:
continue
case <-time.After(2 * time.Second):
t.Errorf("Scheduler failed to execute the scheduled tasks %d run within 2 seconds", i)
}
}
})
t.Run("Verify StartAfter works as expected", func(t *testing.T) {
// Channel for orchestrating when the task ran
doneCh := make(chan struct{})
// Create a Start time
sa := time.Now().Add(10 * time.Second)
// Setup A task
id, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Second),
StartAfter: sa,
TaskFunc: func() error {
doneCh <- struct{}{}
return nil
},
ErrFunc: func(_ error) {},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
defer scheduler.Del(id)
// Make sure it runs especially when we want it too
select {
case <-doneCh:
if time.Now().Before(sa) {
t.Errorf("Task executed before the defined start time now %s, supposed to be %s", time.Now().String(), sa.String())
}
return
case <-time.After(15 * time.Second):
t.Errorf("Scheduler failed to execute the scheduled tasks within 15 seconds")
}
})
}
func TestSchedulerDoesntRun(t *testing.T) {
// Create a base scheduler to use
scheduler := New()
defer scheduler.Stop()
t.Run("Verify Cancelling a StartAfter works as expected", func(t *testing.T) {
// Channel for orchestrating when the task ran
doneCh := make(chan struct{})
// Create a Start time
sa := time.Now().Add(10 * time.Second)
// Setup A task
id, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Second),
StartAfter: sa,
TaskFunc: func() error {
doneCh <- struct{}{}
return nil
},
ErrFunc: func(_ error) {},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
// Remove task before it can be scheduled
scheduler.Del(id)
// Make sure it doesn't run
select {
case <-doneCh:
t.Errorf("Task executed it was supposed to be cancelled")
return
case <-time.After(15 * time.Second):
return
}
})
t.Run("Verify Tasks Dont run when Deleted", func(t *testing.T) {
// Channel for orchestrating when the task ran
doneCh := make(chan struct{})
// Setup A task
id, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error {
doneCh <- struct{}{}
return nil
},
ErrFunc: func(_ error) {},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
defer scheduler.Del(id)
// Make sure it runs especially when we want it too
for i := 0; i < 6; i++ {
select {
case <-doneCh:
if i == 2 {
scheduler.Del(id)
}
if i > 2 {
t.Errorf("Task should not have exceeded 2, count is %d", i)
}
continue
case <-time.After(2 * time.Second):
if i > 2 {
return
}
t.Errorf("Scheduler failed to execute the scheduled tasks %d run within 2 seconds", i)
}
}
})
}
func TestSchedulerExtras(t *testing.T) {
// Create a base scheduler to use
scheduler := New()
defer scheduler.Stop()
t.Run("Verify RunOnce works as expected", func(t *testing.T) {
// Channel for orchestrating when the task ran
doneCh := make(chan struct{})
// Setup A task
id, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Second),
RunOnce: true,
TaskFunc: func() error {
doneCh <- struct{}{}
return nil
},
ErrFunc: func(_ error) {},
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
defer scheduler.Del(id)
// Make sure it runs especially when we want it too
for i := 0; i < 6; i++ {
select {
case <-doneCh:
if i >= 1 {
t.Errorf("Task should not have exceeded 1, count is %d", i)
}
continue
case <-time.After(2 * time.Second):
if i == 1 {
return
}
t.Errorf("Scheduler failed to execute the scheduled tasks %d run within 2 seconds", i)
}
}
})
t.Run("Test ErrFunc gets called on errors", func(t *testing.T) {
// Create a channel to signal function exec
doneCh := make(chan struct{})
// Add task
_, err := scheduler.Add(&Task{
Interval: time.Duration(1 * time.Second),
TaskFunc: func() error { return fmt.Errorf("Errors are bad") },
ErrFunc: func(_ error) { doneCh <- struct{}{} },
})
if err != nil {
t.Errorf("Unexpected errors when scheduling a valid task - %s", err)
}
// Wait for success, or timeout
select {
case <-doneCh:
return
case <-time.After(2 * time.Second):
t.Errorf("Error function was not called when an error occurred")
}
})
}
func TestSingleInstance(t *testing.T) {
// Create a base scheduler to use
scheduler := New()
defer scheduler.Stop()
// Create a counter to track how many times the task is called
counter := NewCounter()
// Create a second counter to track number of executions
counter2 := NewCounter()
// Create an error channel to signal failure
errCh := make(chan error)
// Add a task that will increment the counter
_, err := scheduler.Add(&Task{
Interval: time.Duration(500 * time.Millisecond),
RunSingleInstance: true,
TaskFunc: func() error {
// Increment Concurrent Counter
counter.Inc()
if counter.Val() > 1 {
return fmt.Errorf("Task ran more than once - count %d", counter.Val())
}
// Increment Execution Counter
counter2.Inc()
// Wait for 10 seconds
<-time.After(5 * time.Second)
// Decrement Concurrent Counter
counter.Dec()
return nil
},
ErrFunc: func(e error) {
errCh <- e
},
})
if err != nil {
t.Fatalf("Unexpected errors when scheduling task - %s", err)
}
// Wait for tasks to run and if no error, then we are good
select {
case <-time.After(30 * time.Second):
if counter2.Val() < 4 {
t.Fatalf("Task was not called more than once successfully - count %d", counter2.Val())
}
case e := <-errCh:
t.Fatalf("Error function was called - %s", e)
}
}