Skip to content

Commit cdf4b43

Browse files
committed
fix
1 parent e699258 commit cdf4b43

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

pkg/api/v1/workload_service.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
nameref "github.com/google/go-containerregistry/pkg/name"
15+
1516
regtypes "github.com/stacklok/toolhive-core/registry/types"
1617
groupval "github.com/stacklok/toolhive-core/validation/group"
1718
httpval "github.com/stacklok/toolhive-core/validation/http"
@@ -435,7 +436,10 @@ func validateRuntimeConfig(runtimeConfig *templates.RuntimeConfig) error {
435436
return nil
436437
}
437438

438-
func runtimeConfigForImageBuild(req *createRequest, runtimeConfigOverride *templates.RuntimeConfig) (*templates.RuntimeConfig, error) {
439+
func runtimeConfigForImageBuild(
440+
req *createRequest,
441+
runtimeConfigOverride *templates.RuntimeConfig,
442+
) (*templates.RuntimeConfig, error) {
439443
if runtimeConfigOverride == nil || req == nil {
440444
return nil, nil
441445
}

pkg/api/v1/workloads_types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212

13+
"github.com/stacklok/toolhive-core/permissions"
1314
"github.com/stacklok/toolhive/pkg/auth"
1415
"github.com/stacklok/toolhive/pkg/auth/remote"
1516
"github.com/stacklok/toolhive/pkg/container/templates"
16-
"github.com/stacklok/toolhive-core/permissions"
1717
"github.com/stacklok/toolhive/pkg/runner"
1818
"github.com/stacklok/toolhive/pkg/secrets"
1919
"github.com/stacklok/toolhive/pkg/transport/types"

pkg/vmcp/composer/state_store_test.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ func TestInMemoryStateStore_ListActiveWorkflows(t *testing.T) {
143143
// TestInMemoryStateStore_Cleanup tests automatic cleanup of stale workflows.
144144
func TestInMemoryStateStore_Cleanup(t *testing.T) {
145145
t.Parallel()
146-
// Use very short intervals for testing but with sufficient margin
146+
// Use short intervals with enough margin to reduce CI timing flakiness.
147147
cleanupInterval := 50 * time.Millisecond
148-
maxAge := 50 * time.Millisecond
148+
maxAge := 100 * time.Millisecond
149149

150150
store := NewInMemoryStateStore(cleanupInterval, maxAge).(*inMemoryStateStore)
151151
defer store.Stop()
152152

153153
// Create workflows directly in the store with specific timestamps
154-
veryOldTime := time.Now().Add(-1 * time.Second) // Way older than maxAge
154+
veryOldTime := time.Now().Add(-500 * time.Millisecond) // Well older than maxAge
155155

156156
store.mu.Lock()
157157
// Old completed workflow - should be cleaned up
@@ -169,20 +169,15 @@ func TestInMemoryStateStore_Cleanup(t *testing.T) {
169169
}
170170
store.mu.Unlock()
171171

172-
// Wait for at least 2 cleanup cycles
173-
time.Sleep(150 * time.Millisecond)
172+
require.Eventually(t, func() bool {
173+
store.mu.RLock()
174+
oldExists := store.states["old-workflow"]
175+
runningExists := store.states["running-workflow"]
176+
store.mu.RUnlock()
174177

175-
// Verify cleanup results
176-
store.mu.RLock()
177-
oldExists := store.states["old-workflow"]
178-
runningExists := store.states["running-workflow"]
179-
store.mu.RUnlock()
180-
181-
// Old completed workflow should be cleaned up
182-
assert.Nil(t, oldExists, "old completed workflow should be cleaned up")
183-
184-
// Running workflow should still exist (not a terminal state)
185-
assert.NotNil(t, runningExists, "running workflow should not be cleaned up")
178+
// Old completed workflow should be cleaned up, running workflow must remain.
179+
return oldExists == nil && runningExists != nil
180+
}, 1*time.Second, 25*time.Millisecond, "expected stale terminal workflow to be cleaned up")
186181
}
187182

188183
// TestInMemoryStateStore_GetStats tests statistics retrieval.

0 commit comments

Comments
 (0)