Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
billyb2 committed Jul 29, 2024
1 parent c231251 commit ce89c34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
4 changes: 1 addition & 3 deletions internal/build/imgsrc/ensure_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/haikunator"
"github.com/superfly/flyctl/internal/tracing"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

func EnsureBuilder(ctx context.Context, org *fly.Organization, region string, recreateBuilder bool) (*fly.Machine, *fly.App, error) {
Expand Down Expand Up @@ -148,7 +146,7 @@ const (
)

func validateBuilder(ctx context.Context, app *fly.App) (*fly.Machine, error) {
ctx, span := tracing.GetTracer().Start(ctx, "validate_builder", trace.WithAttributes(attribute.String("bulder_app", app.Name)))
ctx, span := tracing.GetTracer().Start(ctx, "validate_builder")
defer span.End()

if app == nil {
Expand Down
17 changes: 3 additions & 14 deletions internal/build/imgsrc/ensure_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,34 +265,23 @@ func TestRestartBuilderMachine(t *testing.T) {
ctx := context.Background()

couldNotReserveResources := false
waitedForStartOrStop := false
flapsClient := mock.FlapsClient{
RestartFunc: func(ctx context.Context, input fly.RestartMachineInput, nonce string) error {
StartFunc: func(ctx context.Context, machineID string, nonce string) (*fly.MachineStartResponse, error) {
if couldNotReserveResources {
return &flaps.FlapsError{
return nil, &flaps.FlapsError{
OriginalError: fmt.Errorf("failed to restart VM xyzabc: unknown: could not reserve resource for machine: insufficient memory available to fulfill request"),
}
}
return nil
},
WaitFunc: func(ctx context.Context, machine *fly.Machine, state string, timeout time.Duration) (err error) {
if state == "started" || state == "stopped" {
waitedForStartOrStop = true
}

return nil
return nil, nil
},
}

ctx = flapsutil.NewContextWithClient(ctx, &flapsClient)
err := startBuilder(ctx, &fly.Machine{ID: "bigmachine"})
assert.NoError(t, err)
assert.True(t, waitedForStartOrStop)

waitedForStartOrStop = false
couldNotReserveResources = true
err = startBuilder(ctx, &fly.Machine{ID: "bigmachine"})
assert.True(t, waitedForStartOrStop)
assert.Error(t, err)
assert.ErrorIs(t, err, ShouldReplaceBuilderMachine)

Expand Down

0 comments on commit ce89c34

Please sign in to comment.