Skip to content

Commit 45fb006

Browse files
committed
add idle state for interval programs
1 parent d9a4992 commit 45fb006

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

pkg/program/program.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
StateNotStarted ProcessState = iota
3939
StateRunning
4040
StateFinished
41+
StateIdle
4142
StateError
4243
)
4344

@@ -195,6 +196,7 @@ func (p *program) Start(ctx context.Context) (<-chan struct{}, error) {
195196

196197
p.stateLock.Lock()
197198
p.currentRun++
199+
p.overallState = StateIdle
198200
p.stateLock.Unlock()
199201
}
200202
}
@@ -637,6 +639,8 @@ func (p *program) Statistics() Statistics {
637639
switch p.State() {
638640
case StateFinished:
639641
state = "finished"
642+
case StateIdle:
643+
state = "idle"
640644
case StateError:
641645
state = "error"
642646
case StateRunning:

pkg/program/program_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ func TestStatistics(t *testing.T) {
592592
t.Errorf("Expected at least 1 output line, got %d", stats.TotalOutputLines)
593593
}
594594

595+
if stats.State != "idle" {
596+
t.Errorf("Expected interval program state to be idle, got %s", stats.State)
597+
}
598+
595599
stringOutput := stats.String()
596600
if !strings.Contains(stringOutput, "echo-test") {
597601
t.Errorf("Expected string output to contain program name, got: %q", stringOutput)
@@ -637,6 +641,10 @@ func TestStatistics(t *testing.T) {
637641
t.Error("Expected LastError to be set")
638642
}
639643

644+
if stats.State != "error" {
645+
t.Errorf("Expected program state to be error, got %s", stats.State)
646+
}
647+
640648
stringOutput := stats.String()
641649
if !strings.Contains(stringOutput, "failed: 1") {
642650
t.Errorf("Expected string output to show failed runs, got: %q", stringOutput)

0 commit comments

Comments
 (0)