| 178 | } |
| 179 | |
| 180 | func Test_Logger_TimeUpdaterStopsOnDone(t *testing.T) { |
| 181 | t.Parallel() |
| 182 | |
| 183 | var timestamp atomic.Value |
| 184 | timestamp.Store(time.Now().Format(time.RFC3339Nano)) |
| 185 | |
| 186 | done := make(chan struct{}) |
| 187 | cfg := Config{ |
| 188 | Format: "${time}", |
| 189 | TimeFormat: time.RFC3339Nano, |
| 190 | TimeInterval: 5 * time.Millisecond, |
| 191 | timeZoneLocation: time.Local, |
| 192 | TimeDone: done, |
| 193 | } |
| 194 | |
| 195 | stoppedCh := startTimestampUpdaterWithStop(×tamp, &cfg) |
| 196 | |
| 197 | initial, ok := timestamp.Load().(string) |
| 198 | require.True(t, ok) |
| 199 | time.Sleep(20 * time.Millisecond) |
| 200 | updated, ok := timestamp.Load().(string) |
| 201 | require.True(t, ok) |
| 202 | require.NotEqual(t, initial, updated) |
| 203 | |
| 204 | close(done) |
| 205 | select { |
| 206 | case <-stoppedCh: |
| 207 | case <-time.After(time.Second): |
| 208 | t.Fatal("timestamp updater did not stop") |
| 209 | } |
| 210 | stopped, ok := timestamp.Load().(string) |
| 211 | require.True(t, ok) |
| 212 | time.Sleep(20 * time.Millisecond) |
| 213 | finalValue, ok := timestamp.Load().(string) |
| 214 | require.True(t, ok) |
| 215 | require.Equal(t, stopped, finalValue) |
| 216 | } |
| 217 | |
| 218 | func Test_Logger_TimestampUpdater_StopsImmediatelyWithoutTimeTag(t *testing.T) { |
| 219 | t.Parallel() |