Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Sep 4, 2024
1 parent 273dcee commit f6bf629
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 72 deletions.
70 changes: 5 additions & 65 deletions backend/controller/dal/dal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,12 @@ func TestDAL(t *testing.T) {
assert.IsError(t, err, libdal.ErrConflict)
})

t.Run("GetIdleRunnersForLanguage", func(t *testing.T) {
expectedRunner := Runner{
Key: runnerID,
Labels: labels,
Endpoint: "http://localhost:8080",
State: RunnerStateNew,
}
runners, err := dal.GetIdleRunners(ctx, 10, labels)
assert.NoError(t, err)
assert.Equal(t, []Runner{expectedRunner}, runners)
})

expectedRunner := Runner{
Key: runnerID,
Labels: labels,
Endpoint: "http://localhost:8080",
State: RunnerStateReserved,
Deployment: optional.Some(deploymentKey),
Deployment: deploymentKey,
}

t.Run("GetDeploymentsNeedingReconciliation", func(t *testing.T) {
Expand All @@ -167,43 +155,13 @@ func TestDAL(t *testing.T) {
}}, reconcile)
})

t.Run("ReserveRunnerForInvalidDeployment", func(t *testing.T) {
_, err := dal.ReserveRunnerForDeployment(ctx, model.NewDeploymentKey("invalid"), time.Second, labels)
assert.Error(t, err)
assert.IsError(t, err, libdal.ErrNotFound)
assert.EqualError(t, err, "deployment: not found")
})

t.Run("ReserveRunnerForDeployment", func(t *testing.T) {
claim, err := dal.ReserveRunnerForDeployment(ctx, deploymentKey, time.Millisecond*100, labels)
assert.NoError(t, err)
err = claim.Commit(context.Background())
assert.NoError(t, err)
assert.Equal(t, expectedRunner, claim.Runner())
})

t.Run("ExpireRunnerClaims", func(t *testing.T) {
time.Sleep(time.Millisecond * 500)
count, err := dal.ExpireRunnerClaims(ctx)
assert.NoError(t, err)
assert.Equal(t, 1, count)
runners, err := dal.GetIdleRunners(ctx, 10, labels)
assert.NoError(t, err)
assert.Equal(t, 1, len(runners))
})

t.Run("ReserveRunnerForDeploymentFailsOnInvalidDeployment", func(t *testing.T) {
_, err = dal.ReserveRunnerForDeployment(ctx, model.NewDeploymentKey("test"), time.Second, labels)
assert.IsError(t, err, libdal.ErrNotFound)
})

t.Run("UpdateRunnerAssigned", func(t *testing.T) {
err := dal.UpsertRunner(ctx, Runner{
Key: runnerID,
Labels: labels,
Endpoint: "http://localhost:8080",
State: RunnerStateAssigned,
Deployment: optional.Some(deploymentKey),
Deployment: deploymentKey,
})
assert.NoError(t, err)
})
Expand All @@ -222,7 +180,7 @@ func TestDAL(t *testing.T) {
Labels: labels,
Endpoint: "http://localhost:8080",
State: RunnerStateAssigned,
Deployment: optional.Some(deploymentKey),
Deployment: deploymentKey,
}}, runners)
})

Expand Down Expand Up @@ -318,30 +276,12 @@ func TestDAL(t *testing.T) {
Labels: labels,
Endpoint: "http://localhost:8080",
State: RunnerStateAssigned,
Deployment: optional.Some(model.NewDeploymentKey("test")),
Deployment: model.NewDeploymentKey("test"),
})
assert.Error(t, err)
assert.IsError(t, err, libdal.ErrNotFound)
})

t.Run("ReleaseRunnerReservation", func(t *testing.T) {
err = dal.UpsertRunner(ctx, Runner{
Key: runnerID,
Labels: labels,
Endpoint: "http://localhost:8080",
State: RunnerStateNew,
})
assert.NoError(t, err)
})

t.Run("ReserveRunnerForDeploymentAfterRelease", func(t *testing.T) {
claim, err := dal.ReserveRunnerForDeployment(ctx, deploymentKey, time.Second, labels)
assert.NoError(t, err)
err = claim.Commit(context.Background())
assert.NoError(t, err)
assert.Equal(t, expectedRunner, claim.Runner())
})

t.Run("GetRoutingTable", func(t *testing.T) {
_, err := dal.GetRoutingTable(ctx, []string{deployment.Module})
assert.IsError(t, err, libdal.ErrNotFound)
Expand Down Expand Up @@ -425,7 +365,7 @@ func artefactContent(t testing.TB, artefacts []*model.Artefact) [][]byte {
}

func TestRunnerStateFromProto(t *testing.T) {
state := ftlv1.RunnerState_RUNNER_IDLE
state := ftlv1.RunnerState_RUNNER_NEW
assert.Equal(t, RunnerStateNew, RunnerStateFromProto(state))
}

Expand Down
2 changes: 1 addition & 1 deletion backend/controller/scaling/scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func runGrpcScaling(url url.URL, ctx context.Context, handler func(ctx context.C

logger := log.FromContext(ctx)
logger.Debugf("Starting Runner Scaling")
logger.Debugf("Using FTL endpoint: %s", url)
logger.Debugf("Using FTL endpoint: %s", url.String())

rpc.RetryStreamingServerStream(ctx, backoff.Backoff{Max: time.Second}, &ftlv1.PullSchemaRequest{}, client.PullSchema, handler, rpc.AlwaysRetry())
logger.Debugf("Stopped Runner Scaling")
Expand Down
4 changes: 2 additions & 2 deletions internal/buildengine/testdata/alpha/go.sum

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

4 changes: 2 additions & 2 deletions internal/buildengine/testdata/another/go.sum

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

4 changes: 2 additions & 2 deletions internal/buildengine/testdata/other/go.sum

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

0 comments on commit f6bf629

Please sign in to comment.