MCPcopy Create free account
hub / github.com/QuantumNous/new-api / TestSystemTaskUpdatesRequireCurrentLock

Function TestSystemTaskUpdatesRequireCurrentLock

model/system_task_test.go:310–327  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

308}
309
310func TestSystemTaskUpdatesRequireCurrentLock(t *testing.T) {
311 truncateTables(t)
312
313 task, err := CreateSystemTask(SystemTaskTypeLogCleanup, nil, nil)
314 require.NoError(t, err)
315
316 runnerID := "runner-a"
317 _, claimed, err := ClaimSystemTask(task.ID, SystemTaskTypeLogCleanup, runnerID, common.GetTimestamp()+60)
318 require.NoError(t, err)
319 require.True(t, claimed)
320
321 require.NoError(t, DB.Model(&SystemTaskLock{}).
322 Where("task_id = ?", task.TaskID).
323 Updates(map[string]any{"locked_by": "runner-b"}).Error)
324
325 assert.ErrorIs(t, UpdateSystemTaskState(task.TaskID, runnerID, testSystemTaskState{Progress: 10}), ErrSystemTaskLockLost)
326 assert.ErrorIs(t, FinishSystemTask(task.TaskID, runnerID, SystemTaskStatusSucceeded, nil, ""), ErrSystemTaskLockLost)
327}
328
329func TestSystemTaskUpdatesRequireUnexpiredLock(t *testing.T) {
330 truncateTables(t)

Callers

nothing calls this directly

Calls 6

GetTimestampFunction · 0.92
truncateTablesFunction · 0.85
CreateSystemTaskFunction · 0.85
ClaimSystemTaskFunction · 0.85
UpdateSystemTaskStateFunction · 0.85
FinishSystemTaskFunction · 0.85

Tested by

no test coverage detected