mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* 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
52 lines
1023 B
Go
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()
|
|
}
|