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

chore(coderd/coderdtest): wait for provisioner daemons to be connected#15936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 3 commits intomainfromcj/flake/await-provisioner-daemon-connected
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionscoderd/coderdtest/coderdtest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -631,6 +631,7 @@ func NewTaggedProvisionerDaemon(t testing.TB, coderAPI *coderd.API, name string,
assert.NoError(t, err)
}()

connectedCh := make(chan struct{})
daemon := provisionerd.New(func(dialCtx context.Context) (provisionerdproto.DRPCProvisionerDaemonClient, error) {
return coderAPI.CreateInMemoryTaggedProvisionerDaemon(dialCtx, name, []codersdk.ProvisionerType{codersdk.ProvisionerTypeEcho}, provisionerTags)
}, &provisionerd.Options{
Expand All@@ -640,7 +641,12 @@ func NewTaggedProvisionerDaemon(t testing.TB, coderAPI *coderd.API, name string,
Connector: provisionerd.LocalProvisioners{
string(database.ProvisionerTypeEcho): sdkproto.NewDRPCProvisionerClient(echoClient),
},
InitConnectionCh: connectedCh,
})
// Wait for the provisioner daemon to connect before continuing.
// Users of this function tend to assume that the provisioner is connected
// and ready to use when that may not strictly be the case.
<-connectedCh
closer := NewProvisionerDaemonCloser(daemon)
t.Cleanup(func() {
_ = closer.Close()
Expand Down
4 changes: 2 additions & 2 deletionscoderd/templateversions_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,8 +172,8 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
require.Equal(t, provisionersdk.ScopeOrganization, version.Job.Tags[provisionersdk.TagScope])
if assert.Equal(t, version.Job.Status, codersdk.ProvisionerJobPending) {
assert.NotNil(t, version.MatchedProvisioners)
assert.Equal(t, version.MatchedProvisioners.Available, 1)
assert.Equal(t, version.MatchedProvisioners.Count, 1)
assert.Equal(t,1,version.MatchedProvisioners.Available)
assert.Equal(t,1,version.MatchedProvisioners.Count)
assert.True(t, version.MatchedProvisioners.MostRecentlySeen.Valid)
}

Expand Down
23 changes: 18 additions & 5 deletionsprovisionerd/provisionerd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,6 +60,7 @@ type Options struct {
UpdateInterval time.Duration
LogBufferInterval time.Duration
Connector Connector
InitConnectionCh chan struct{} // only to be used in tests
}

// New creates and starts a provisioner daemon.
Expand All@@ -84,6 +85,9 @@ func New(clientDialer Dialer, opts *Options) *Server {
mets := NewMetrics(reg)
opts.Metrics = &mets
}
if opts.InitConnectionCh == nil {
opts.InitConnectionCh = make(chan struct{})
}

ctx, ctxCancel := context.WithCancel(context.Background())
daemon := &Server{
Expand All@@ -93,11 +97,12 @@ func New(clientDialer Dialer, opts *Options) *Server {
clientDialer: clientDialer,
clientCh: make(chan proto.DRPCProvisionerDaemonClient),

closeContext: ctx,
closeCancel: ctxCancel,
closedCh: make(chan struct{}),
shuttingDownCh: make(chan struct{}),
acquireDoneCh: make(chan struct{}),
closeContext: ctx,
closeCancel: ctxCancel,
closedCh: make(chan struct{}),
shuttingDownCh: make(chan struct{}),
acquireDoneCh: make(chan struct{}),
initConnectionCh: opts.InitConnectionCh,
}

daemon.wg.Add(2)
Expand All@@ -115,6 +120,11 @@ type Server struct {

wg sync.WaitGroup

// initConnectionCh will receive when the daemon connects to coderd for the
// first time.
initConnectionCh chan struct{}
initConnectionOnce sync.Once

// mutex protects all subsequent fields
mutex sync.Mutex
// closeContext is canceled when we start closing.
Expand DownExpand Up@@ -231,6 +241,9 @@ connectLoop:
}
p.opts.Logger.Info(p.closeContext, "successfully connected to coderd")
retrier.Reset()
p.initConnectionOnce.Do(func() {
close(p.initConnectionCh)
})

// serve the client until we are closed or it disconnects
for {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp