mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-12 06:28:50 +00:00
bunch of probably useless micro optimisation
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
"src/task_tracker/api"
|
||||
"src/task_tracker/storage"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -134,7 +135,7 @@ func TestGetLogs(t *testing.T) {
|
||||
"test": "value",
|
||||
}).Error("error")
|
||||
|
||||
r := getLogs(time.Now().Add(time.Second*-150).Unix(), logrus.DebugLevel)
|
||||
r := getLogs(time.Now().Add(time.Second*-150).Unix(), storage.DEBUG)
|
||||
|
||||
if r.Ok != true {
|
||||
t.Error()
|
||||
@@ -162,7 +163,7 @@ func TestGetLogs(t *testing.T) {
|
||||
|
||||
func TestGetLogsInvalid(t *testing.T) {
|
||||
|
||||
r := getLogs(-1, logrus.ErrorLevel)
|
||||
r := getLogs(-1, storage.ERROR)
|
||||
|
||||
if r.Ok != false {
|
||||
t.Error()
|
||||
@@ -173,7 +174,7 @@ func TestGetLogsInvalid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func getLogs(since int64, level logrus.Level) *api.GetLogResponse {
|
||||
func getLogs(since int64, level storage.LogLevel) *api.GetLogResponse {
|
||||
|
||||
r := Post(fmt.Sprintf("/logs"), api.GetLogRequest{
|
||||
Since: since,
|
||||
|
||||
@@ -2,11 +2,13 @@ package test
|
||||
|
||||
import (
|
||||
"src/task_tracker/api"
|
||||
"src/task_tracker/config"
|
||||
"src/task_tracker/storage"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkCreateTask(b *testing.B) {
|
||||
func BenchmarkCreateTaskRemote(b *testing.B) {
|
||||
|
||||
resp := createProject(api.CreateProjectRequest{
|
||||
Name: "BenchmarkCreateTask" + strconv.Itoa(b.N),
|
||||
@@ -27,3 +29,44 @@ func BenchmarkCreateTask(b *testing.B) {
|
||||
}, worker)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCreateTask(b *testing.B) {
|
||||
|
||||
config.SetupConfig()
|
||||
db := storage.Database{}
|
||||
|
||||
project, _ := db.SaveProject(&storage.Project{
|
||||
Priority: 1,
|
||||
Id: 1,
|
||||
Version: "bmcreatetask",
|
||||
Public: true,
|
||||
Motd: "bmcreatetask",
|
||||
Name: "BenchmarkCreateTask" + strconv.Itoa(b.N),
|
||||
GitRepo: "benchmark_test" + strconv.Itoa(b.N),
|
||||
})
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = db.SaveTask(&storage.Task{}, project, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTest(t *testing.T) {
|
||||
|
||||
config.SetupConfig()
|
||||
db := storage.Database{}
|
||||
|
||||
project, _ := db.SaveProject(&storage.Project{
|
||||
Priority: 1,
|
||||
Id: 1,
|
||||
Version: "bmcreatetask",
|
||||
Public: true,
|
||||
Motd: "bmcreatetask",
|
||||
Name: "BenchmarkCreateTask",
|
||||
GitRepo: "benchmark_test",
|
||||
})
|
||||
|
||||
for i := 0; i < 1000000; i++ {
|
||||
_ = db.SaveTask(&storage.Task{}, project, 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,10 +162,10 @@ func TestCreateGetTask(t *testing.T) {
|
||||
if taskResp.Task.Id == 0 {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Recipe != "{\"url\":\"test\"}" {
|
||||
if string(taskResp.Task.Recipe) != "{\"url\":\"test\"}" {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Status != "new" {
|
||||
if taskResp.Task.Status != 1 {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.MaxRetries != 3 {
|
||||
|
||||
@@ -3,17 +3,6 @@ DROP TABLE IF EXISTS worker_identity, worker, project, task, log_entry,
|
||||
DROP TYPE IF EXISTS status;
|
||||
DROP TYPE IF EXISTS log_level;
|
||||
|
||||
CREATE TYPE status as ENUM (
|
||||
'new',
|
||||
'failed',
|
||||
'closed',
|
||||
'timeout'
|
||||
);
|
||||
|
||||
CREATE TYPE log_level as ENUM (
|
||||
'fatal', 'panic', 'error', 'warning', 'info', 'debug', 'trace'
|
||||
);
|
||||
|
||||
CREATE TABLE worker_identity
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
@@ -53,25 +42,24 @@ CREATE TABLE worker_has_access_to_project
|
||||
|
||||
CREATE TABLE task
|
||||
(
|
||||
hash64 BIGINT DEFAULT NULL UNIQUE,
|
||||
id SERIAL PRIMARY KEY,
|
||||
priority INTEGER DEFAULT 0,
|
||||
project INTEGER REFERENCES project (id),
|
||||
assignee INTEGER REFERENCES worker (id),
|
||||
retries INTEGER DEFAULT 0,
|
||||
max_retries INTEGER,
|
||||
status Status DEFAULT 'new',
|
||||
recipe TEXT,
|
||||
max_assign_time INTEGER DEFAULT 0,
|
||||
assign_time INTEGER DEFAULT 0,
|
||||
hash64 BIGINT DEFAULT NULL UNIQUE
|
||||
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
|
||||
);
|
||||
|
||||
CREATE TABLE log_entry
|
||||
(
|
||||
level log_level,
|
||||
level INTEGER,
|
||||
message TEXT,
|
||||
message_data TEXT,
|
||||
timestamp INT
|
||||
timestamp INTEGER
|
||||
);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user