Skip to content

Commit

Permalink
🐛 don't keep closed unprocessed runtimes in coordinator (#4017)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored May 16, 2024
1 parent 6a8116b commit 66f4671
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions providers/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (c *coordinator) unsafeRefreshRuntimes() {
var remaining []*Runtime
for i := range c.unprocessedRuntimes {
rt := c.unprocessedRuntimes[i]
if rt.isClosed {
continue
}
if asset := rt.asset(); asset == nil || !c.unsafeSetAssetRuntime(asset, rt) {
remaining = append(remaining, rt)
}
Expand Down
42 changes: 42 additions & 0 deletions providers/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,48 @@ func TestRemoveRuntime_StopUnusedProvider(t *testing.T) {
assert.Empty(t, c.runningByID)
}

func TestUnprocessedProviders_RemoveClosed(t *testing.T) {
ctrl := gomock.NewController(t)

// Setup 1 provider with 1 runtime
mockPlugin1 := NewMockProviderPlugin(ctrl)
p1 := &RunningProvider{
ID: "provider1",
Plugin: mockPlugin1,
}

c := &coordinator{
runtimes: map[string]*Runtime{},
runningByID: map[string]*RunningProvider{},
unprocessedRuntimes: []*Runtime{
{
isClosed: true,
providers: map[string]*ConnectedProvider{
"provider2": {Instance: p1},
},
Provider: &ConnectedProvider{
Instance: p1,
Connection: &pp.ConnectRes{},
},
},
{
providers: map[string]*ConnectedProvider{
"provider2": {Instance: p1},
},
Provider: &ConnectedProvider{
Instance: p1,
Connection: &pp.ConnectRes{},
},
},
},
}

c.unsafeRefreshRuntimes()

// The unprocessed runtimes should be 1 since one of them was closed
assert.Len(t, c.unprocessedRuntimes, 1)
}

func TestRemoveRuntime_RemoveDeadProvider(t *testing.T) {
ctrl := gomock.NewController(t)

Expand Down

0 comments on commit 66f4671

Please sign in to comment.