Fix server file browse flow
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"browser.local/platform/domain"
|
||||
)
|
||||
@@ -98,6 +100,34 @@ func TestCoreServiceRunJobClaimNoJob(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoreServiceRunJobClaimWithWaitWakesOnCreate(t *testing.T) {
|
||||
svc, sessionToken := newRegisteredRunJobService(t)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
resultCh := make(chan domain.RunJobClaimResult, 1)
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
claim, err := svc.ClaimRunJobWithWait(ctx, domain.RunJobClaim{RunEndpointID: "run-local", SessionToken: sessionToken, Capabilities: []string{"process.start"}, Capacity: domain.RunCapacity{MaxJobs: 4}, WaitSeconds: 10})
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
resultCh <- claim
|
||||
}()
|
||||
waitForRunJobWaiter(t, svc, "run-local")
|
||||
createQueuedRunJob(t, svc, "job-wait", "idem-wait")
|
||||
select {
|
||||
case err := <-errCh:
|
||||
t.Fatalf("claim wait failed: %v", err)
|
||||
case claim := <-resultCh:
|
||||
if !claim.HasJob || claim.Job == nil || claim.Job.JobID != "job-wait" {
|
||||
t.Fatalf("expected wait claim to return created job, got %+v", claim)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatalf("claim wait timed out: %v", ctx.Err())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoreServiceRunJobClaimSkipsServerFileCapabilityWithoutDeclaration(t *testing.T) {
|
||||
svc := newTestCoreService()
|
||||
plugin, endpoint := createPluginAndRunEndpoint(t, svc)
|
||||
@@ -314,3 +344,18 @@ func createQueuedRunJob(t *testing.T, svc *CoreService, id string, idempotencyKe
|
||||
}
|
||||
return job
|
||||
}
|
||||
|
||||
func waitForRunJobWaiter(t *testing.T, svc *CoreService, runEndpointID string) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(500 * time.Millisecond)
|
||||
for time.Now().Before(deadline) {
|
||||
svc.jobWaitMu.Lock()
|
||||
count := len(svc.jobWaiters[runEndpointID])
|
||||
svc.jobWaitMu.Unlock()
|
||||
if count > 0 {
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
t.Fatalf("waiter for %s was not registered", runEndpointID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user