Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions e2e/framework/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,19 @@ func (f *Framework) DevsyWorkspaceDelete(
return f.ExecCommand(ctx, false, true, fmt.Sprintf("deleted workspace %s", workspace), baseArgs)
}

// CleanupWorkspace gives cleanup a fresh, bounded context. Ginkgo cleanup may
// run after the spec context has expired, so inheriting its cancellation can
// silently skip the workspace deletion.
// DetachedCleanupContext bounds cleanup work to timeout without inheriting
// parent's cancellation. Ginkgo cleanup may run after the spec context has
// expired, and inheriting that cancellation silently skips the cleanup.
func DetachedCleanupContext(
parent context.Context,
timeout time.Duration,
) (context.Context, context.CancelFunc) {
return context.WithTimeout(context.WithoutCancel(parent), timeout)
}

// CleanupWorkspace deletes workspace under a DetachedCleanupContext.
func (f *Framework) CleanupWorkspace(ctx context.Context, workspace string) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), time.Minute)
cleanupCtx, cancel := DetachedCleanupContext(ctx, time.Minute)
defer cancel()
err := f.DevsyWorkspaceDelete(cleanupCtx, workspace)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/up/microsandbox_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *microsandboxTestSession) copyWorkspace(source string) string {
func (s *microsandboxTestSession) addProvider(ctx context.Context, source, name string) {
framework.ExpectNoError(s.framework.DevsyProviderAdd(ctx, source, "--name", name))
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
return s.framework.DevsyProviderDelete(cleanupCtx, name)
})
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/up/provider_microsandbox_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (fixture *compatibilityFixture) registerCleanup() {
// Faults are cleared independently so a failed workspace cleanup cannot block fallback.
ginkgo.DeferCleanup(fixture.shim.restoreEnvironment)
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
fixture.shim.clearVersionFault()
out, err := microsandboxResourceCommand(cleanupCtx, "list", "--quiet")
Expand All @@ -136,7 +136,7 @@ func (fixture *compatibilityFixture) registerCleanup() {
return nil
})
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
fixture.shim.clearVersionFault()
return fixture.framework.CleanupWorkspace(cleanupCtx, fixture.hostPath)
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/up/provider_microsandbox_consumer_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func runMicrosandboxConsumerAttempt(ctx context.Context, attempt microsandboxCon

host := newMicrosandboxConsumerHost(ctx, providerName, workspaceID, consumerProvider)
ginkgo.DeferCleanup(func(cleanupCtx ginkgo.SpecContext) error {
deleteCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
deleteCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
return host.DeleteDevContainer(deleteCtx, workspaceID)
})
Expand Down Expand Up @@ -191,7 +191,7 @@ func newMicrosandboxConsumerRegistry(handler http.Handler) *registryfixture.Serv
}

func closeMicrosandboxConsumerRegistry(ctx context.Context, fixture *registryfixture.Server) error {
closeCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Second)
closeCtx, cancel := framework.DetachedCleanupContext(ctx, 30*time.Second)
defer cancel()
return fixture.Close(closeCtx)
}
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/up/provider_microsandbox_egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func newMicrosandboxEgressEndpoint(ctx context.Context) *microsandboxEgressEndpo
finished := make(chan error, 1)
go func() { finished <- server.Serve(listener) }()
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), 10*time.Second)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, 10*time.Second)
defer cancel()
closeErr := server.Close()
select {
Expand Down Expand Up @@ -297,7 +297,7 @@ func createMicrosandboxEgressInterface(ctx context.Context, name, address string
// v0.7.7 classifies this benchmark range as Public and dials non-gateway IPs directly.
framework.ExpectNoError(microsandboxEgressIP(ctx, "link", "add", "name", name, "type", "dummy"))
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
return microsandboxEgressIP(cleanupCtx, "link", "delete", "dev", name)
})
Expand Down Expand Up @@ -425,7 +425,7 @@ func cleanupMicrosandboxEgressProvider(
f *framework.Framework,
provider string,
) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(ctx, time.Minute)
defer cancel()
return f.DevsyProviderDelete(cleanupCtx, provider)
}
12 changes: 6 additions & 6 deletions e2e/tests/up/provider_microsandbox_ephemeral.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var _ = ginkgo.Describe("microsandbox ephemeral root parity",
f.DevsyProviderAdd(ctx, provider.source, "--name", provider.name),
)
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(
context.WithoutCancel(cleanupCtx),
cleanupCtx, cancel := framework.DetachedCleanupContext(
cleanupCtx,
time.Minute,
)
defer cancel()
Expand All @@ -55,8 +55,8 @@ var _ = ginkgo.Describe("microsandbox ephemeral root parity",
if ownedLabel == "" {
return nil
}
cleanupCtx, cancel := context.WithTimeout(
context.WithoutCancel(cleanupCtx),
cleanupCtx, cancel := framework.DetachedCleanupContext(
cleanupCtx,
time.Minute,
)
defer cancel()
Expand All @@ -82,8 +82,8 @@ var _ = ginkgo.Describe("microsandbox ephemeral root parity",
if !volumeOwned {
return nil
}
cleanupCtx, cancel := context.WithTimeout(
context.WithoutCancel(cleanupCtx),
cleanupCtx, cancel := framework.DetachedCleanupContext(
cleanupCtx,
time.Minute,
)
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/up/provider_microsandbox_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (fixture *microsandboxMigrationFixture) registerCleanup() {
if !fixture.volumeOwned {
return nil
}
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
out, err := microsandboxResourceCommand(cleanupCtx, "volume", "rm", fixture.volume)
if err != nil {
Expand All @@ -126,7 +126,7 @@ func (fixture *microsandboxMigrationFixture) registerCleanup() {
return nil
})
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
out, err := microsandboxResourceCommand(cleanupCtx, "list", "--quiet")
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions e2e/tests/up/provider_microsandbox_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ var _ = ginkgo.Describe("microsandbox mount parity",
)
framework.ExpectNoError(err)
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(
context.WithoutCancel(cleanupCtx), time.Minute,
cleanupCtx, cancel := framework.DetachedCleanupContext(
cleanupCtx,
time.Minute,
)
defer cancel()
_, err := f.ExecCommandOutput(
Expand Down Expand Up @@ -292,9 +293,7 @@ func storeMicrosandboxSecret(
)
framework.ExpectNoError(err)
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(
context.WithoutCancel(cleanupCtx), time.Minute,
)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
_, err := f.ExecCommandOutput(
cleanupCtx,
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/up/provider_microsandbox_recreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (f *safeRecreateFixture) registerCleanup() {
if !f.volumeOwned {
return nil
}
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
out, err := microsandboxResourceCommand(cleanupCtx, "volume", "rm", f.volume)
if err != nil {
Expand All @@ -157,7 +157,7 @@ func (f *safeRecreateFixture) registerCleanup() {
return nil
})
ginkgo.DeferCleanup(func(cleanupCtx context.Context) error {
cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(cleanupCtx), time.Minute)
cleanupCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, time.Minute)
defer cancel()
out, err := microsandboxResourceCommand(cleanupCtx, "list", "--quiet")
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions e2e/tests/up/provider_microsandbox_remote_agent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ var _ = ginkgo.Describe("published MicroSandbox provider remote agent binaries",
)
server := startRemoteAgentArtifactServer(runtimeBytes, agentPath)
ginkgo.DeferCleanup(func(cleanupCtx ginkgo.SpecContext) error {
closeCtx, cancel := context.WithTimeout(
context.WithoutCancel(cleanupCtx), 10*time.Second,
)
closeCtx, cancel := framework.DetachedCleanupContext(cleanupCtx, 10*time.Second)
defer cancel()
return server.close(closeCtx)
})
Expand All @@ -122,8 +120,9 @@ var _ = ginkgo.Describe("published MicroSandbox provider remote agent binaries",

workspace := session.newWorkspace()
ginkgo.DeferCleanup(func(cleanupCtx ginkgo.SpecContext) error {
boundedCtx, cancel := context.WithTimeout(
context.WithoutCancel(cleanupCtx), 20*time.Second,
boundedCtx, cancel := framework.DetachedCleanupContext(
cleanupCtx,
20*time.Second,
)
defer cancel()
return removeRemoteAgentContainer(boundedCtx, containerName)
Expand Down
Loading