mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 21:59:05 +08:00
44 lines
1005 B
Go
44 lines
1005 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package glog_test
|
|
|
|
import (
|
|
"github.com/gogf/gf/os/gfile"
|
|
"github.com/gogf/gf/os/glog"
|
|
"github.com/gogf/gf/os/gtime"
|
|
"github.com/gogf/gf/test/gtest"
|
|
"github.com/gogf/gf/text/gstr"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func Test_Concurrent(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
c := 1000
|
|
l := glog.New()
|
|
s := "@1234567890#"
|
|
f := "test.log"
|
|
p := gfile.TempDir(gtime.TimestampNanoStr())
|
|
t.Assert(l.SetPath(p), nil)
|
|
defer gfile.Remove(p)
|
|
wg := sync.WaitGroup{}
|
|
ch := make(chan struct{})
|
|
for i := 0; i < c; i++ {
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
<-ch
|
|
l.File(f).Stdout(false).Print(s)
|
|
}()
|
|
}
|
|
close(ch)
|
|
wg.Wait()
|
|
content := gfile.GetContents(gfile.Join(p, f))
|
|
t.Assert(gstr.Count(content, s), c)
|
|
})
|
|
}
|