Files
mattermost/shared/mlog/log_test.go
Jesús Espino 9cc5089af8 Moving mlog to corelibs (#16915)
* Moving mlog to corelibs

* Regenerating app layers

* Fix golangci-lint problem

* Fixing golangci-lint errors

* Renaming from corelibs to shared

* Renaming from corelibs to shared

* Fixing import

* Fixing merge problems

* Fixing build
2021-03-05 09:18:37 +01:00

52 lines
1023 B
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package mlog_test
import (
"context"
"sync"
"testing"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
)
// Test race condition when shutting down advanced logging. This test must run with the -race flag in order to verify
// that there is no race.
func TestLogger_ShutdownAdvancedLoggingRace(t *testing.T) {
logger := mlog.NewLogger(&mlog.LoggerConfiguration{
EnableConsole: true,
ConsoleJson: true,
EnableFile: false,
FileLevel: mlog.LevelInfo,
})
started := make(chan bool)
ctx, cancel := context.WithCancel(context.Background())
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
started <- true
for {
select {
case <-ctx.Done():
return
default:
logger.Debug("testing...")
}
}
}()
<-started
err := logger.ShutdownAdvancedLogging(ctx)
require.NoError(t, err)
cancel()
wg.Wait()
}