Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ committed Feb 20, 2024
1 parent b425e4f commit 806f833
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions pkg/component/runtime/manager_fake_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3134,7 +3134,7 @@ LOOP:
require.NoError(t, err)
}

func (suite *FakeInputSuite) TestManager_OutputChange() {
func (suite *FakeInputSuite) TestManager_StartStopComponent() {
t := suite.T()

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -3278,15 +3278,17 @@ func (suite *FakeInputSuite) TestManager_OutputChange() {
subErrCh0,
&state,
[]client.UnitState{client.UnitStateHealthy, client.UnitStateStopped})
stateProgressionCh <- progressionStep{IDComp0, state}
stateProgressionCh <- progressionStep{
componentID: IDComp0, state: state}

case state := <-sub1.Ch():
t.Logf("component %s state changed: %+v", IDComp1, state)
signalState(
subErrCh1,
&state,
[]client.UnitState{client.UnitStateHealthy})
stateProgressionCh <- progressionStep{IDComp1, state}
stateProgressionCh <- progressionStep{
componentID: IDComp1, state: state}
}
}
}()
Expand All @@ -3312,7 +3314,8 @@ func (suite *FakeInputSuite) TestManager_OutputChange() {
time.Sleep(100 * time.Millisecond)
m.Update(component.Model{Components: components})
err = <-m.errCh
require.NoError(t, err)
require.NoError(t, err, "expected no error from the manager when applying"+
"the 1st component model")

updateSleep := 300 * time.Millisecond
if runtime.GOOS == component.Windows {
Expand All @@ -3322,7 +3325,8 @@ func (suite *FakeInputSuite) TestManager_OutputChange() {
time.Sleep(updateSleep)
m.Update(component.Model{Components: components2})
err = <-m.errCh
require.NoError(t, err)
require.NoError(t, err, "expected no error from the manager when applying"+
"the 2nd component model")

count := 0
timeout := 30 * time.Second
Expand Down Expand Up @@ -3359,21 +3363,40 @@ LOOP:

// check progression, require stop fake-0 before start fake-1
stateProgressionWG.Wait()
comp0Stopped := false
var comp0Started, comp0Healthy, comp0Stopped, comp0Failed,
comp1Started, comp1Failed bool
for _, step := range stateProgression {
if step.componentID == IDComp0 &&
step.state.State == client.UnitStateStopped {
comp0Stopped = true
}
if step.componentID == IDComp1 &&
step.state.State == client.UnitStateStarting {
require.True(t, comp0Stopped)
break
switch step.componentID {
case IDComp0:
switch step.state.State {
case client.UnitStateStarting:
comp0Started = true
case client.UnitStateHealthy:
comp0Healthy = true
case client.UnitStateStopped:
comp0Stopped = true
case client.UnitStateDegraded, client.UnitStateFailed:
comp0Failed = true
}
case IDComp1:
switch step.state.State {
case client.UnitStateStarting:
comp1Started = true
case client.UnitStateDegraded, client.UnitStateFailed:
comp1Failed = true
}
}
}
assert.Truef(t, comp0Started, "component %s did not start", IDComp0)
assert.Truef(t, comp0Healthy, "component %s was not healty", IDComp0)
assert.Truef(t, comp0Stopped, "component %s did not stop", IDComp0)
assert.Falsef(t, comp0Failed, "component %s failed", IDComp0)

assert.Truef(t, comp1Started, "component %s did not start", IDComp1)
assert.Falsef(t, comp1Failed, "component %s failed", IDComp1)

err = <-errCh
require.NoError(t, err)
assert.NoError(t, err, "Manager.Run returned and error")
}

func (suite *FakeInputSuite) TestManager_Chunk() {
Expand Down

0 comments on commit 806f833

Please sign in to comment.