File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
examples/supervisor/supervisor Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 4
4
"fmt"
5
5
"os"
6
6
"testing"
7
-
7
+ "time"
8
+
8
9
"github.com/stretchr/testify/assert"
9
10
10
11
"github.com/open-telemetry/opamp-go/internal"
@@ -62,3 +63,33 @@ agent:
62
63
63
64
supervisor .Shutdown ()
64
65
}
66
+
67
+ func TestShutdownRaceCondition (t * testing.T ) {
68
+ tmpDir := changeCurrentDir (t )
69
+ os .WriteFile ("supervisor.yaml" , []byte (fmt .Sprintf (`
70
+ server:
71
+ endpoint: ws://127.0.0.1:4320/v1/opamp
72
+ agent:
73
+ executable: %s/dummy_agent.sh` , tmpDir )), 0644 )
74
+
75
+ os .WriteFile ("dummy_agent.sh" , []byte ("#!/bin/sh\n sleep 9999\n " ), 0755 )
76
+
77
+ startOpampServer (t )
78
+
79
+ // There's no great way to ensure Shutdown gets called before Start.
80
+ // The DelayLogger ensures some delay before the goroutine gets started.
81
+ var supervisor * Supervisor
82
+ var err error
83
+ supervisor , err = NewSupervisor (& internal.DelayLogger {})
84
+ supervisor .Shutdown ()
85
+ supervisor .hasNewConfig <- struct {}{}
86
+
87
+ assert .NoError (t , err )
88
+
89
+ // The Shutdown method has been called before the runAgentProcess goroutine
90
+ // gets started and has a chance to load a new process. Make sure no PID
91
+ // has been launched.
92
+ assert .Never (t , func () bool {
93
+ return supervisor .commander .Pid () != 0
94
+ }, 2 * time .Second , 10 * time .Millisecond )
95
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package internal
2
2
3
3
import (
4
4
"context"
5
+ "time"
5
6
6
7
"github.com/open-telemetry/opamp-go/client/types"
7
8
)
@@ -12,3 +13,12 @@ type NopLogger struct{}
12
13
13
14
func (l * NopLogger ) Debugf (ctx context.Context , format string , v ... interface {}) {}
14
15
func (l * NopLogger ) Errorf (ctx context.Context , format string , v ... interface {}) {}
16
+
17
+ type DelayLogger struct {}
18
+
19
+ func (l * DelayLogger ) Debugf (ctx context.Context , format string , v ... interface {}) {
20
+ time .Sleep (10 * time .Millisecond )
21
+ }
22
+ func (l * DelayLogger ) Errorf (ctx context.Context , format string , v ... interface {}) {
23
+ time .Sleep (10 * time .Millisecond )
24
+ }
You can’t perform that action at this time.
0 commit comments