| 92 | } |
| 93 | |
| 94 | func TestLoggerLogsMultipleTasksWithoutBlocking(t *testing.T) { |
| 95 | var buf bytes.Buffer |
| 96 | |
| 97 | l := NewLogger(&buf, ForceProgress(true)) |
| 98 | l.throttle = 0 |
| 99 | t1, t2 := make(chan *Update), make(chan *Update) |
| 100 | |
| 101 | l.widthFn = func() int { return 0 } |
| 102 | l.Enqueue(ChanTask(t1)) |
| 103 | |
| 104 | t1 <- &Update{"first", time.Now(), false} |
| 105 | l.Enqueue(ChanTask(t2)) |
| 106 | close(t1) |
| 107 | t2 <- &Update{"second", time.Now(), false} |
| 108 | close(t2) |
| 109 | |
| 110 | l.Close() |
| 111 | |
| 112 | assert.Equal(t, strings.Join([]string{ |
| 113 | "first\r", |
| 114 | "first, done.\n", |
| 115 | "second\r", |
| 116 | "second, done.\n", |
| 117 | }, ""), buf.String()) |
| 118 | } |
| 119 | |
| 120 | func TestLoggerThrottlesWrites(t *testing.T) { |
| 121 | var buf bytes.Buffer |