Fix decreased prewarming pool due to inactivity timer.
When allocations fail and restart they are added again to the idle runners. The bug fixed with this commit is that the inactivity timer was not stopped at the restart. This led to the idle runner being removed when the timer expired.
This commit is contained in:
@ -190,8 +190,11 @@ func (m *NomadRunnerManager) onAllocationStopped(runnerID string) (alreadyRemove
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, stillActive := m.usedRunners.Get(runnerID)
|
r, stillActive := m.usedRunners.Get(runnerID)
|
||||||
m.usedRunners.Delete(runnerID)
|
if stillActive {
|
||||||
|
r.StopTimeout()
|
||||||
|
m.usedRunners.Delete(runnerID)
|
||||||
|
}
|
||||||
|
|
||||||
environment, ok := m.environments.Get(environmentID.ToString())
|
environment, ok := m.environments.Get(environmentID.ToString())
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -367,6 +367,42 @@ func (s *ManagerTestSuite) TestOnAllocationAdded() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ManagerTestSuite) TestOnAllocationStopped() {
|
||||||
|
s.Run("stops inactivity timer", func() {
|
||||||
|
testStoppedInactivityTimer(s, true)
|
||||||
|
})
|
||||||
|
s.Run("stops inactivity timer - counter check", func() {
|
||||||
|
testStoppedInactivityTimer(s, false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func testStoppedInactivityTimer(s *ManagerTestSuite, stopAllocation bool) {
|
||||||
|
s.T().Helper()
|
||||||
|
environment, ok := s.nomadRunnerManager.environments.Get(tests.DefaultEnvironmentIDAsString)
|
||||||
|
s.Require().True(ok)
|
||||||
|
mockIdleRunners(environment.(*ExecutionEnvironmentMock))
|
||||||
|
|
||||||
|
inactivityTimerCalled := false
|
||||||
|
environment.AddRunner(NewNomadJob(tests.DefaultRunnerID, []nomadApi.PortMapping{}, s.apiMock, func(r Runner) error {
|
||||||
|
inactivityTimerCalled = true
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
|
||||||
|
runner, err := s.nomadRunnerManager.Claim(defaultEnvironmentID, 1)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().False(runner.TimeoutPassed())
|
||||||
|
s.Require().False(inactivityTimerCalled)
|
||||||
|
|
||||||
|
if stopAllocation {
|
||||||
|
alreadyRemoved := s.nomadRunnerManager.onAllocationStopped(runner.ID())
|
||||||
|
s.False(alreadyRemoved)
|
||||||
|
}
|
||||||
|
|
||||||
|
<-time.After(time.Second + tests.ShortTimeout)
|
||||||
|
s.NotEqual(stopAllocation, runner.TimeoutPassed())
|
||||||
|
s.NotEqual(stopAllocation, inactivityTimerCalled)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNomadRunnerManager_Load(t *testing.T) {
|
func TestNomadRunnerManager_Load(t *testing.T) {
|
||||||
apiMock := &nomad.ExecutorAPIMock{}
|
apiMock := &nomad.ExecutorAPIMock{}
|
||||||
mockWatchAllocations(apiMock)
|
mockWatchAllocations(apiMock)
|
||||||
|
Reference in New Issue
Block a user