mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-14 07:19:02 +00:00
Performance patch, version bump
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/simon987/task_tracker/api"
|
||||
"github.com/simon987/task_tracker/storage"
|
||||
"golang.org/x/time/rate"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -136,7 +137,7 @@ func TestUpdateProjectValid(t *testing.T) {
|
||||
Hidden: true,
|
||||
Paused: true,
|
||||
AssignRate: 1,
|
||||
SubmitRate: 2,
|
||||
SubmitRate: 0,
|
||||
Version: "VersionB",
|
||||
}, pid, testAdminCtx)
|
||||
|
||||
@@ -173,7 +174,7 @@ func TestUpdateProjectValid(t *testing.T) {
|
||||
if proj.Project.AssignRate != 1 {
|
||||
t.Error()
|
||||
}
|
||||
if proj.Project.SubmitRate != 2 {
|
||||
if proj.Project.SubmitRate != rate.Inf {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package test
|
||||
|
||||
import (
|
||||
"github.com/simon987/task_tracker/api"
|
||||
"github.com/simon987/task_tracker/storage"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
@@ -17,6 +18,13 @@ func BenchmarkCreateTaskRemote(b *testing.B) {
|
||||
|
||||
worker := genWid()
|
||||
|
||||
requestAccess(api.CreateWorkerAccessRequest{
|
||||
Submit: true,
|
||||
Assign: false,
|
||||
Project: resp.Content.Id,
|
||||
}, worker)
|
||||
acceptAccessRequest(resp.Content.Id, worker.Id, testAdminCtx)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
createTask(api.SubmitTaskRequest{
|
||||
@@ -27,3 +35,36 @@ func BenchmarkCreateTaskRemote(b *testing.B) {
|
||||
}, worker)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCreateTask(b *testing.B) {
|
||||
|
||||
resp := createProjectAsAdmin(api.CreateProjectRequest{
|
||||
Name: "BenchmarkCreateTask" + strconv.Itoa(b.N),
|
||||
GitRepo: "benchmark_test" + strconv.Itoa(b.N),
|
||||
Version: "f09e8c9r0w839x0c43",
|
||||
CloneUrl: "http://localhost",
|
||||
})
|
||||
|
||||
worker := genWid()
|
||||
|
||||
requestAccess(api.CreateWorkerAccessRequest{
|
||||
Submit: true,
|
||||
Assign: false,
|
||||
Project: resp.Content.Id,
|
||||
}, worker)
|
||||
acceptAccessRequest(resp.Content.Id, worker.Id, testAdminCtx)
|
||||
|
||||
db := storage.New()
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
p := db.GetProject(resp.Content.Id)
|
||||
for i := 0; i < b.N; i++ {
|
||||
db.SaveTask(&storage.Task{
|
||||
Project: p,
|
||||
Priority: 0,
|
||||
Recipe: "{}",
|
||||
MaxRetries: 1,
|
||||
}, resp.Content.Id, 0, worker.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,6 +405,7 @@ func TestReleaseTaskSuccess(t *testing.T) {
|
||||
Project: pid,
|
||||
Recipe: "{}",
|
||||
MaxRetries: 3,
|
||||
Hash64: math.MaxInt64,
|
||||
}, worker)
|
||||
|
||||
task := getTaskFromProject(pid, worker).Content.Task
|
||||
@@ -923,25 +924,20 @@ func TestTaskSubmitInvalidDoesntGiveRateLimit(t *testing.T) {
|
||||
|
||||
func TestBulkTaskSubmitValid(t *testing.T) {
|
||||
|
||||
proj := createProjectAsAdmin(api.CreateProjectRequest{
|
||||
Name: "testbulksubmit",
|
||||
CloneUrl: "testbulkprojectsubmit",
|
||||
GitRepo: "testbulkprojectsubmit",
|
||||
}).Content.Id
|
||||
|
||||
r := bulkSubmitTask(api.BulkSubmitTaskRequest{
|
||||
Requests: []api.SubmitTaskRequest{
|
||||
{
|
||||
Recipe: "1234",
|
||||
Project: proj,
|
||||
Project: testProject,
|
||||
},
|
||||
{
|
||||
Recipe: "1234",
|
||||
Project: proj,
|
||||
Project: testProject,
|
||||
},
|
||||
{
|
||||
Recipe: "1234",
|
||||
Project: proj,
|
||||
Project: testProject,
|
||||
Hash64: 8565956259293726066,
|
||||
},
|
||||
},
|
||||
}, testWorker)
|
||||
@@ -1015,6 +1011,44 @@ func TestBulkTaskSubmitInvalid2(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskGetUnauthorizedWithCache(t *testing.T) {
|
||||
|
||||
pid := createProjectAsAdmin(api.CreateProjectRequest{
|
||||
Name: "testtaskgetunauthorizedcache",
|
||||
GitRepo: "testtaskgetunauthorizedcache",
|
||||
CloneUrl: "testtaskgettunauthorizedcache",
|
||||
}).Content.Id
|
||||
|
||||
w := genWid()
|
||||
|
||||
requestAccess(api.CreateWorkerAccessRequest{
|
||||
Project: pid,
|
||||
Submit: true,
|
||||
Assign: true,
|
||||
}, w)
|
||||
acceptAccessRequest(pid, w.Id, testAdminCtx)
|
||||
|
||||
r1 := createTask(api.SubmitTaskRequest{
|
||||
Project: pid,
|
||||
Recipe: "ssss",
|
||||
}, w)
|
||||
|
||||
// removed access, cache should be invalidated
|
||||
rejectAccessRequest(pid, w.Id, testAdminCtx)
|
||||
|
||||
r2 := createTask(api.SubmitTaskRequest{
|
||||
Project: pid,
|
||||
Recipe: "ssss",
|
||||
}, w)
|
||||
|
||||
if r1.Ok != true {
|
||||
t.Error()
|
||||
}
|
||||
if r2.Ok != false {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func bulkSubmitTask(request api.BulkSubmitTaskRequest, worker *storage.Worker) (ar api.JsonResponse) {
|
||||
r := Post("/task/bulk_submit", request, worker, nil)
|
||||
UnmarshalResponse(r, &ar)
|
||||
|
||||
25
test/schema.sql
Executable file → Normal file
25
test/schema.sql
Executable file → Normal file
@@ -41,6 +41,8 @@ CREATE TABLE worker_access
|
||||
request boolean,
|
||||
primary key (worker, project)
|
||||
);
|
||||
CREATE INDEX worker_index ON worker_access (worker);
|
||||
CREATE INDEX project_index ON worker_access (project);
|
||||
|
||||
CREATE TABLE task
|
||||
(
|
||||
@@ -50,22 +52,28 @@ CREATE TABLE task
|
||||
assignee INTEGER REFERENCES worker (id),
|
||||
max_assign_time INTEGER DEFAULT 0,
|
||||
assign_time INTEGER DEFAULT NULL,
|
||||
verification_count INTEGER DEFAULT 0,
|
||||
verification_count SMALLINT DEFAULT 0,
|
||||
priority SMALLINT DEFAULT 0,
|
||||
retries SMALLINT DEFAULT 0,
|
||||
max_retries SMALLINT,
|
||||
status SMALLINT DEFAULT 1,
|
||||
recipe TEXT,
|
||||
UNIQUE (project, hash64)
|
||||
recipe TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX priority_desc_index ON task (priority DESC);
|
||||
CREATE INDEX assignee_index ON task (assignee);
|
||||
CREATE INDEX verifcnt_index ON task (verification_count);
|
||||
CREATE UNIQUE INDEX project_hash_unique ON task (project, hash64);
|
||||
|
||||
CREATE TABLE worker_verifies_task
|
||||
(
|
||||
verification_hash BIGINT NOT NULL,
|
||||
task BIGINT REFERENCES task (id) ON DELETE CASCADE NOT NULL,
|
||||
worker INT REFERENCES worker (id) NOT NULL
|
||||
verification_hash BIGINT NOT NULL,
|
||||
task INT REFERENCES task (id) ON DELETE CASCADE NOT NULL,
|
||||
worker INT REFERENCES worker (id) NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX task_index ON worker_verifies_task (task);
|
||||
|
||||
CREATE TABLE log_entry
|
||||
(
|
||||
level INTEGER NOT NULL,
|
||||
@@ -150,7 +158,7 @@ $$
|
||||
DECLARE
|
||||
res INT = NULL;
|
||||
BEGIN
|
||||
DELETE FROM task WHERE id = tid AND assignee = wid AND verification_count < 2 RETURNING project INTO res;
|
||||
DELETE FROM task WHERE id = tid AND assignee = wid AND verification_count = 1 RETURNING project INTO res;
|
||||
|
||||
IF res IS NULL THEN
|
||||
INSERT INTO worker_verifies_task (worker, verification_hash, task)
|
||||
@@ -171,11 +179,10 @@ BEGIN
|
||||
LIMIT 1) >= task.verification_count RETURNING task.id INTO res;
|
||||
|
||||
IF res IS NULL THEN
|
||||
UPDATE task SET assignee= NULL WHERE id = tid AND assignee = wid;
|
||||
UPDATE task SET assignee=NULL WHERE id = tid AND assignee = wid;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
RETURN res IS NOT NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user