MCPcopy
hub / github.com/gofiber/fiber / Test_Logger_TimeUpdaterStopsOnDone

Function Test_Logger_TimeUpdaterStopsOnDone

middleware/logger/logger_test.go:180–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func 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(&timestamp, &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
218func Test_Logger_TimestampUpdater_StopsImmediatelyWithoutTimeTag(t *testing.T) {
219 t.Parallel()

Callers

nothing calls this directly

Calls 6

StoreMethod · 0.80
FormatMethod · 0.65
LoadMethod · 0.65
FatalMethod · 0.65
NowMethod · 0.45

Tested by

no test coverage detected