Skip to content

Instantly share code, notes, and snippets.

@hovsep
Created February 23, 2026 20:11
Show Gist options
  • Select an option

  • Save hovsep/c7eae07398591ac7eae26cc253730d87 to your computer and use it in GitHub Desktop.

Select an option

Save hovsep/c7eae07398591ac7eae26cc253730d87 to your computer and use it in GitHub Desktop.
time_test
func Test_Time(t *testing.T) {
tests := []struct {
name string
assertions func(t *testing.T, sim *step_sim.Simulation)
}{
{
name: "time advances in timer",
assertions: func(t *testing.T, sim *step_sim.Simulation) {
var observedSimWallTime []time.Time
timeComponent := sim.FM.ComponentByName("time")
require.NotNil(t, timeComponent)
timeComponent.SetupHooks(func(hooks *component.Hooks) {
hooks.AfterActivation(func(activationContext *component.ActivationContext) error {
tickSig := timeComponent.OutputByName("tick").Signals().First()
require.NotNil(t, tickSig)
_, _, simWallTime, _, err := helper.UnpackTick(tickSig)
require.NoError(t, err)
// Observe and collect sim wall time after every iteration
observedSimWallTime = append(observedSimWallTime, simWallTime)
return nil
})
})
helper.WithRunningSimulation(sim, defaultSimulationDuration, func() {
assert.IsIncreasing(t, observedSimWallTime)
})
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmdChan := make(chan step_sim.Command)
fm := getSimulationMesh()
sim := step_sim.NewSimulation(context.Background(), cmdChan, fm)
if tt.assertions != nil {
tt.assertions(t, sim)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment