Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcea4851

Browse files
committed
prevent race
1 parent8aaa6d5 commitcea4851

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

‎agent/agent_test.go‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,14 +2525,21 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
25252525
t.Skip("Skipping non-linux environment")
25262526
}
25272527

2528-
varbuf bytes.Buffer
2529-
log:=slog.Make(sloghuman.Sink(&buf)).Leveled(slog.LevelDebug)
2528+
var (
2529+
buf bytes.Buffer
2530+
wr=&syncWriter{
2531+
w:&buf,
2532+
}
2533+
)
2534+
log:=slog.Make(sloghuman.Sink(wr)).Leveled(slog.LevelDebug)
25302535

25312536
_,_,_,_,_=setupAgent(t, agentsdk.Manifest{},0,func(c*agenttest.Client,o*agent.Options) {
25322537
o.Logger=log
25332538
})
25342539

25352540
require.Eventually(t,func()bool {
2541+
wr.mu.Lock()
2542+
deferwr.mu.Unlock()
25362543
returnstrings.Contains(buf.String(),"process priority not enabled")
25372544
},testutil.WaitLong,testutil.IntervalFast)
25382545
})
@@ -2544,8 +2551,13 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
25442551
t.Skip("Skipping linux environment")
25452552
}
25462553

2547-
varbuf bytes.Buffer
2548-
log:=slog.Make(sloghuman.Sink(&buf)).Leveled(slog.LevelDebug)
2554+
var (
2555+
buf bytes.Buffer
2556+
wr=&syncWriter{
2557+
w:&buf,
2558+
}
2559+
)
2560+
log:=slog.Make(sloghuman.Sink(wr)).Leveled(slog.LevelDebug)
25492561

25502562
_,_,_,_,_=setupAgent(t, agentsdk.Manifest{},0,func(c*agenttest.Client,o*agent.Options) {
25512563
o.Logger=log
@@ -2554,6 +2566,9 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
25542566
o.EnvironmentVariables=map[string]string{agent.EnvProcPrioMgmt:"1"}
25552567
})
25562568
require.Eventually(t,func()bool {
2569+
wr.mu.Lock()
2570+
deferwr.mu.Unlock()
2571+
25572572
returnstrings.Contains(buf.String(),"process priority not enabled")
25582573
},testutil.WaitLong,testutil.IntervalFast)
25592574
})
@@ -2580,3 +2595,14 @@ func verifyCollectedMetrics(t *testing.T, expected []agentsdk.AgentMetric, actua
25802595
}
25812596
returntrue
25822597
}
2598+
2599+
typesyncWriterstruct {
2600+
mu sync.Mutex
2601+
w io.Writer
2602+
}
2603+
2604+
func (s*syncWriter)Write(p []byte) (int,error) {
2605+
s.mu.Lock()
2606+
defers.mu.Unlock()
2607+
returns.w.Write(p)
2608+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp