Skip to content

Commit

Permalink
NOISSUE - Remove duplicate event (#308)
Browse files Browse the repository at this point in the history
* remove duplicate event

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* generate string

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* add test cases

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

---------

Signed-off-by: Sammy Oina <sammyoina@gmail.com>
  • Loading branch information
SammyOina authored Nov 11, 2024
1 parent 1e285e3 commit 04b51a6
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
3 changes: 2 additions & 1 deletion agent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const (
Completed
Terminated
Warning
Starting
)

const (
Expand Down Expand Up @@ -352,7 +353,7 @@ func (as *agentService) Attestation(ctx context.Context, reportData [ReportDataS
}

func (as *agentService) runComputation(state statemachine.State) {
as.publishEvent(InProgress.String())(state)
as.publishEvent(Starting.String())(state)
as.logger.Debug("computation run started")
defer func() {
if as.runError != nil {
Expand Down
67 changes: 67 additions & 0 deletions agent/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,70 @@ func TestConcurrency(t *testing.T) {
t.Errorf("Unexpected final state: %v", finalState)
}
}

func TestAgentEventString(t *testing.T) {
tests := []struct {
event AgentEvent
want string
}{
{Start, "Start"},
{ManifestReceived, "ManifestReceived"},
{AlgorithmReceived, "AlgorithmReceived"},
{DataReceived, "DataReceived"},
{RunComplete, "RunComplete"},
{ResultsConsumed, "ResultsConsumed"},
{RunFailed, "RunFailed"},
{AgentEvent(-1), "AgentEvent(-1)"},
}

for _, tt := range tests {
if got := tt.event.String(); got != tt.want {
t.Errorf("AgentEvent.String() = %v, want %v", got, tt.want)
}
}
}

func TestAgentStateString(t *testing.T) {
tests := []struct {
state AgentState
want string
}{
{Idle, "Idle"},
{ReceivingManifest, "ReceivingManifest"},
{ReceivingAlgorithm, "ReceivingAlgorithm"},
{ReceivingData, "ReceivingData"},
{Running, "Running"},
{ConsumingResults, "ConsumingResults"},
{Complete, "Complete"},
{Failed, "Failed"},
{AgentState(-1), "AgentState(-1)"},
}

for _, tt := range tests {
if got := tt.state.String(); got != tt.want {
t.Errorf("AgentState.String() = %v, want %v", got, tt.want)
}
}
}

func TestStatusString(t *testing.T) {
tests := []struct {
status Status
want string
}{
{IdleState, "IdleState"},
{InProgress, "InProgress"},
{Ready, "Ready"},
{Completed, "Completed"},
{Terminated, "Terminated"},
{Warning, "Warning"},
{Starting, "Starting"},
{Status(uint8(8)), "Status(8)"},
}

for _, tt := range tests {
if got := tt.status.String(); got != tt.want {
t.Errorf("Status.String() = %v, want %v", got, tt.want)
}
}
}
5 changes: 3 additions & 2 deletions agent/status_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04b51a6

Please sign in to comment.