From ce5344d9c7516d5b5aed8f090003b32ea69dd383 Mon Sep 17 00:00:00 2001 From: simon987 Date: Sun, 24 Feb 2019 13:34:13 -0500 Subject: [PATCH] Fix a task chain bug --- jenkins/Jenkinsfile | 4 ++++ schema.sql | 3 ++- test/api_task_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++ test/schema.sql | 3 ++- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 126ba5a..353d36b 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -4,6 +4,10 @@ remote.host = 'localhost' remote.user = 'simon' remote.identityFile = '/var/lib/jenkins/.ssh/id_rsa' remote.knownHosts = '/var/lib/jenkins/.ssh/known_hosts' +remote.allowAnyHosts = true +remote.retryCount = 3 +remote.retryWaitSec = 3 +logLevel = 'FINER' pipeline { agent none diff --git a/schema.sql b/schema.sql index 7fb2665..878f063 100755 --- a/schema.sql +++ b/schema.sql @@ -113,7 +113,8 @@ BEGIN priority, retries, max_retries, status, recipe) VALUES (old.hash64, chain, NULL, old.max_assign_time, NULL, old.verification_count, old.priority, 0, old.max_retries, 1, - old.recipe); + old.recipe) + ON CONFLICT DO NOTHING; end if; end if; RETURN OLD; diff --git a/test/api_task_test.go b/test/api_task_test.go index 582e059..40ea7b0 100644 --- a/test/api_task_test.go +++ b/test/api_task_test.go @@ -881,6 +881,55 @@ func TestTaskGetUnauthorized(t *testing.T) { } } +func TestTaskChainCausesConflict(t *testing.T) { + p1 := createProjectAsAdmin(api.CreateProjectRequest{ + Name: "testtaskchainconflict", + CloneUrl: "testtaskchainconfflict", + Public: false, + }).Content.Id + + p2 := createProjectAsAdmin(api.CreateProjectRequest{ + Name: "testtaskchainconflict2", + CloneUrl: "testtaskchainconfflict2", + Public: false, + Chain: p1, + }).Content.Id + + w := genWid() + requestAccess(api.CreateWorkerAccessRequest{ + Project: p1, + Assign: true, + Submit: true, + }, w) + requestAccess(api.CreateWorkerAccessRequest{ + Project: p2, + Assign: true, + Submit: true, + }, w) + acceptAccessRequest(p1, w.Id, testAdminCtx) + acceptAccessRequest(p2, w.Id, testAdminCtx) + + createTask(api.SubmitTaskRequest{ + Project: p2, + Recipe: " ", + Hash64: 1, + }, w) + createTask(api.SubmitTaskRequest{ + Project: p1, + Recipe: " ", + Hash64: 1, + }, w) + tid := getTaskFromProject(p2, w).Content.Task.Id + resp := releaseTask(api.ReleaseTaskRequest{ + TaskId: tid, + Result: storage.TR_OK, + }, w) + + if resp.Ok != true { + t.Error() + } +} + func createTask(request api.SubmitTaskRequest, worker *storage.Worker) (ar api.JsonResponse) { r := Post("/task/submit", request, worker, nil) UnmarshalResponse(r, &ar) diff --git a/test/schema.sql b/test/schema.sql index 7fb2665..878f063 100755 --- a/test/schema.sql +++ b/test/schema.sql @@ -113,7 +113,8 @@ BEGIN priority, retries, max_retries, status, recipe) VALUES (old.hash64, chain, NULL, old.max_assign_time, NULL, old.verification_count, old.priority, 0, old.max_retries, 1, - old.recipe); + old.recipe) + ON CONFLICT DO NOTHING; end if; end if; RETURN OLD;