-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: runner unable to re-register (#707)
- Loading branch information
Showing
6 changed files
with
126 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package runner | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/leg100/otf/internal/logr" | ||
"github.com/leg100/otf/internal/resource" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRunner(t *testing.T) { | ||
updates := make(chan RunnerStatus) | ||
wantID := resource.NewID(resource.RunnerKind) | ||
|
||
r, err := newRunner( | ||
logr.Discard(), | ||
&fakeRunnerClient{registeredID: wantID, updates: updates}, | ||
&fakeOperationSpawner{}, | ||
false, | ||
Config{}, | ||
) | ||
require.NoError(t, err) | ||
|
||
// Terminate runner at end of test | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
|
||
startErr := make(chan error) | ||
go func() { | ||
startErr <- r.Start(ctx) | ||
}() | ||
|
||
// Test that runner registers itself | ||
assert.Equal(t, &RunnerMeta{ID: wantID}, <-r.registered) | ||
// Terminate runner | ||
cancel() | ||
// Test that runner sends final status update | ||
assert.Equal(t, RunnerExited, <-updates) | ||
} | ||
|
||
type fakeRunnerClient struct { | ||
client | ||
|
||
registeredID resource.ID | ||
updates chan RunnerStatus | ||
} | ||
|
||
func (f *fakeRunnerClient) register(ctx context.Context, opts registerOptions) (*RunnerMeta, error) { | ||
return &RunnerMeta{ID: f.registeredID}, nil | ||
} | ||
|
||
func (f *fakeRunnerClient) getJobs(ctx context.Context, agentID resource.ID) ([]*Job, error) { | ||
// Block until context canceled | ||
<-ctx.Done() | ||
return nil, nil | ||
} | ||
|
||
func (f *fakeRunnerClient) updateStatus(ctx context.Context, agentID resource.ID, status RunnerStatus) error { | ||
f.updates <- status | ||
return nil | ||
} | ||
|
||
type fakeOperationSpawner struct { | ||
operationSpawner | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package runner | ||
|
||
import "github.com/leg100/otf/internal/authz" | ||
|
||
// unregistered describes a runner that is not yet registered. | ||
type unregistered struct { | ||
// unregistered is a subject only for the purposes of satisfying the | ||
// token-handling middleware which doesn't call any of the interface | ||
// methods. | ||
authz.Subject | ||
|
||
// pool is non-nil if the runner is an agent. | ||
pool *RunnerMetaAgentPool | ||
} |