Download this file
| 1 | package activator |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | // Each mark records the time since the one before it, under the step's |
| 9 | // name, so the line reads as where the wake spent its time. |
| 10 | func TestWakeStepsNameTheTimeSinceThePreviousMark(t *testing.T) { |
| 11 | t0 := time.Unix(1000, 0) |
| 12 | var s wakeSteps |
| 13 | s.begin(t0) |
| 14 | s.mark(t0.Add(3*time.Millisecond), "checks") |
| 15 | s.mark(t0.Add(83*time.Millisecond), "lease") |
| 16 | s.mark(t0.Add(83400*time.Microsecond), "restore") |
| 17 | s.mark(t0.Add(752*time.Millisecond), "spawn") |
| 18 | if got, want := s.String(), "checks 3ms, lease 80ms, restore 0s, spawn 669ms"; got != want { |
| 19 | t.Errorf("String = %q, want %q", got, want) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // A wake that never began (the claim path, a nil entry) has nothing to say. |
| 24 | func TestWakeStepsWithoutABeginRecordNothing(t *testing.T) { |
| 25 | var s wakeSteps |
| 26 | s.mark(time.Unix(1000, 0), "lease") |
| 27 | if got := s.String(); got != "" { |
| 28 | t.Errorf("String = %q, want empty", got) |
| 29 | } |
| 30 | } |
| 31 | |