mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-12 06:28:50 +00:00
task verification (not 100% tested)
This commit is contained in:
@@ -145,10 +145,11 @@ func TestCreateGetTask(t *testing.T) {
|
||||
worker := genWid()
|
||||
|
||||
createTask(api.CreateTaskRequest{
|
||||
Project: resp.Id,
|
||||
Recipe: "{\"url\":\"test\"}",
|
||||
MaxRetries: 3,
|
||||
Priority: 9999,
|
||||
Project: resp.Id,
|
||||
Recipe: "{\"url\":\"test\"}",
|
||||
MaxRetries: 3,
|
||||
Priority: 9999,
|
||||
VerificationCount: 12,
|
||||
}, worker)
|
||||
|
||||
taskResp := getTaskFromProject(resp.Id, worker)
|
||||
@@ -156,6 +157,9 @@ func TestCreateGetTask(t *testing.T) {
|
||||
if taskResp.Ok != true {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.VerificationCount != 12 {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Priority != 9999 {
|
||||
t.Error()
|
||||
}
|
||||
@@ -398,8 +402,8 @@ func TestReleaseTaskSuccess(t *testing.T) {
|
||||
task := getTaskFromProject(pid, worker).Task
|
||||
|
||||
releaseResp := releaseTask(api.ReleaseTaskRequest{
|
||||
TaskId: task.Id,
|
||||
Success: true,
|
||||
TaskId: task.Id,
|
||||
Result: storage.TR_OK,
|
||||
}, worker)
|
||||
|
||||
if releaseResp.Ok != true {
|
||||
@@ -503,6 +507,138 @@ func TestCreateStringCollision(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCannotVerifySameTaskTwice(t *testing.T) {
|
||||
|
||||
pid := createProject(api.CreateProjectRequest{
|
||||
Priority: 1,
|
||||
GitRepo: "verifysametasktwice",
|
||||
CloneUrl: "verifysametasktwice",
|
||||
Motd: "verifysametasktwice",
|
||||
Public: true,
|
||||
Name: "verifysametasktwice",
|
||||
Version: "verifysametasktwice",
|
||||
}).Id
|
||||
|
||||
w := genWid()
|
||||
|
||||
createTask(api.CreateTaskRequest{
|
||||
VerificationCount: 2,
|
||||
Project: pid,
|
||||
Recipe: "verifysametasktwice",
|
||||
}, w)
|
||||
|
||||
task := getTaskFromProject(pid, w).Task
|
||||
rlr := releaseTask(api.ReleaseTaskRequest{
|
||||
Result: storage.TR_OK,
|
||||
TaskId: task.Id,
|
||||
Verification: 123,
|
||||
}, w)
|
||||
|
||||
if rlr.Updated != false {
|
||||
t.Error()
|
||||
}
|
||||
|
||||
sameTask := getTaskFromProject(pid, w)
|
||||
|
||||
if sameTask.Ok != false {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerification2(t *testing.T) {
|
||||
|
||||
pid := createProject(api.CreateProjectRequest{
|
||||
Priority: 1,
|
||||
GitRepo: "verify2",
|
||||
CloneUrl: "verify2",
|
||||
Motd: "verify2",
|
||||
Public: true,
|
||||
Name: "verify2",
|
||||
Version: "verify2",
|
||||
}).Id
|
||||
|
||||
w := genWid()
|
||||
w2 := genWid()
|
||||
w3 := genWid()
|
||||
|
||||
createTask(api.CreateTaskRequest{
|
||||
VerificationCount: 2,
|
||||
Project: pid,
|
||||
Recipe: "verify2",
|
||||
}, w)
|
||||
|
||||
task := getTaskFromProject(pid, w).Task
|
||||
rlr := releaseTask(api.ReleaseTaskRequest{
|
||||
Result: storage.TR_OK,
|
||||
TaskId: task.Id,
|
||||
Verification: 123,
|
||||
}, w)
|
||||
|
||||
if rlr.Updated != false {
|
||||
t.Error()
|
||||
}
|
||||
|
||||
task2 := getTaskFromProject(pid, w2).Task
|
||||
rlr2 := releaseTask(api.ReleaseTaskRequest{
|
||||
Result: storage.TR_OK,
|
||||
Verification: 1,
|
||||
TaskId: task2.Id,
|
||||
}, w2)
|
||||
|
||||
if rlr2.Updated != false {
|
||||
t.Error()
|
||||
}
|
||||
|
||||
task3 := getTaskFromProject(pid, w3).Task
|
||||
rlr3 := releaseTask(api.ReleaseTaskRequest{
|
||||
Result: storage.TR_OK,
|
||||
Verification: 123,
|
||||
TaskId: task3.Id,
|
||||
}, w3)
|
||||
|
||||
if rlr3.Updated != true {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func TestReleaseTaskFail(t *testing.T) {
|
||||
|
||||
pid := createProject(api.CreateProjectRequest{
|
||||
Priority: 1,
|
||||
GitRepo: "releasefail",
|
||||
CloneUrl: "releasefail",
|
||||
Motd: "releasefail",
|
||||
Public: true,
|
||||
Name: "releasefail",
|
||||
Version: "releasefail",
|
||||
}).Id
|
||||
|
||||
w := genWid()
|
||||
|
||||
createTask(api.CreateTaskRequest{
|
||||
MaxRetries: 0,
|
||||
Project: pid,
|
||||
VerificationCount: 1,
|
||||
Recipe: "releasefail",
|
||||
}, w)
|
||||
|
||||
task := getTaskFromProject(pid, w).Task
|
||||
|
||||
resp := releaseTask(api.ReleaseTaskRequest{
|
||||
Result: storage.TR_FAIL,
|
||||
TaskId: task.Id,
|
||||
Verification: 1,
|
||||
}, w)
|
||||
|
||||
if resp.Updated != true {
|
||||
t.Error()
|
||||
}
|
||||
if resp.Ok != true {
|
||||
t.Error()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func createTask(request api.CreateTaskRequest, worker *storage.Worker) *api.CreateTaskResponse {
|
||||
|
||||
r := Post("/task/create", request, worker)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
DROP TABLE IF EXISTS worker_identity, worker, project, task, log_entry,
|
||||
worker_has_access_to_project, manager, manager_has_role_on_project;
|
||||
worker_has_access_to_project, manager, manager_has_role_on_project, project_monitoring, worker_verifies_task;
|
||||
DROP TYPE IF EXISTS status;
|
||||
DROP TYPE IF EXISTS log_level;
|
||||
|
||||
@@ -23,14 +23,15 @@ CREATE TABLE worker
|
||||
|
||||
CREATE TABLE project
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
priority INTEGER DEFAULT 0,
|
||||
name TEXT UNIQUE,
|
||||
clone_url TEXT,
|
||||
git_repo TEXT UNIQUE,
|
||||
version TEXT,
|
||||
motd TEXT,
|
||||
public boolean
|
||||
id SERIAL PRIMARY KEY,
|
||||
priority INTEGER DEFAULT 0,
|
||||
name TEXT UNIQUE,
|
||||
clone_url TEXT,
|
||||
git_repo TEXT UNIQUE,
|
||||
version TEXT,
|
||||
motd TEXT,
|
||||
public boolean,
|
||||
closed_task_count INT DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE worker_has_access_to_project
|
||||
@@ -42,17 +43,25 @@ CREATE TABLE worker_has_access_to_project
|
||||
|
||||
CREATE TABLE task
|
||||
(
|
||||
hash64 BIGINT DEFAULT NULL UNIQUE,
|
||||
id SERIAL PRIMARY KEY,
|
||||
project INTEGER REFERENCES project (id),
|
||||
assignee INTEGER REFERENCES worker (id),
|
||||
max_assign_time INTEGER DEFAULT 0,
|
||||
assign_time INTEGER DEFAULT 0,
|
||||
priority SMALLINT DEFAULT 0,
|
||||
retries SMALLINT DEFAULT 0,
|
||||
max_retries SMALLINT,
|
||||
status SMALLINT DEFAULT 1,
|
||||
recipe TEXT
|
||||
hash64 BIGINT DEFAULT NULL UNIQUE,
|
||||
id SERIAL PRIMARY KEY,
|
||||
project INTEGER REFERENCES project (id),
|
||||
assignee INTEGER REFERENCES worker (id),
|
||||
max_assign_time INTEGER DEFAULT 0,
|
||||
assign_time INTEGER DEFAULT 0,
|
||||
verification_count INTEGER DEFAULT 0,
|
||||
priority SMALLINT DEFAULT 0,
|
||||
retries SMALLINT DEFAULT 0,
|
||||
max_retries SMALLINT,
|
||||
status SMALLINT DEFAULT 1,
|
||||
recipe TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE worker_verifies_task
|
||||
(
|
||||
verification_hash BIGINT,
|
||||
task BIGINT REFERENCES task (id) ON DELETE CASCADE,
|
||||
worker INT REFERENCES worker (id)
|
||||
);
|
||||
|
||||
CREATE TABLE log_entry
|
||||
@@ -76,4 +85,25 @@ CREATE TABLE manager_has_role_on_project
|
||||
manager INTEGER REFERENCES manager (id),
|
||||
role SMALLINT,
|
||||
project INTEGER REFERENCES project (id)
|
||||
);
|
||||
);
|
||||
|
||||
CREATE TABLE project_monitoring
|
||||
(
|
||||
project INT REFERENCES project (id),
|
||||
new_task_count INT,
|
||||
failed_task_count INT,
|
||||
closed_task_count INT
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION on_task_delete_proc() RETURNS TRIGGER AS
|
||||
$$
|
||||
BEGIN
|
||||
UPDATE project SET closed_task_count=closed_task_count + 1 WHERE id = OLD.project;
|
||||
RETURN OLD;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE TRIGGER on_task_delete
|
||||
BEFORE DELETE
|
||||
ON task
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE on_task_delete_proc();
|
||||
|
||||
Reference in New Issue
Block a user