From 63ad0394687bde6dba5dd271ba76231140759eeb Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Wed, 2 Oct 2024 13:37:51 -0700 Subject: [PATCH] Race in setting Config.Level: Add failing test --- logger_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/logger_test.go b/logger_test.go index 8e9d5a9..63b5a05 100644 --- a/logger_test.go +++ b/logger_test.go @@ -957,6 +957,21 @@ func TestInvalidFile(t *testing.T) { } } +func TestConcurrentLevelSet(t *testing.T) { + // This test is to make sure that setting the log level concurrently + // doesn't cause a -race failure. Shows up in dflag/ for instance with configmap changes. + var wg sync.WaitGroup + wg.Add(int(Fatal - Verbose)) + for i := Verbose; i < Fatal; i++ { + go func() { + SetLogLevel(i) + wg.Done() + }() + } + wg.Wait() + SetLogLevel(Info) +} + // --- Benchmarks // This `discard` is like io.Discard, except that io.Discard is checked explicitly