Skip to content

Commit cea4851

Browse files
committed
prevent race
1 parent 8aaa6d5 commit cea4851

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-
var buf 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+
defer wr.mu.Unlock()
25362543
return strings.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-
var buf 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+
defer wr.mu.Unlock()
2571+
25572572
return strings.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
return true
25822597
}
2598+
2599+
type syncWriter struct {
2600+
mu sync.Mutex
2601+
w io.Writer
2602+
}
2603+
2604+
func (s *syncWriter) Write(p []byte) (int, error) {
2605+
s.mu.Lock()
2606+
defer s.mu.Unlock()
2607+
return s.w.Write(p)
2608+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy