diff --git a/Makefile b/Makefile index af08537..91c4ff3 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ all: clean build server: swagger dep $(GOBUILD) -o server ./cmd/server -runner: dep +runner: swagger dep $(GOBUILD) -o runner ./cmd/runner build: runner server diff --git a/internal/api/problem/details.go b/internal/api/problem/details.go index 3df21e6..fee3e40 100644 --- a/internal/api/problem/details.go +++ b/internal/api/problem/details.go @@ -39,6 +39,7 @@ func (h *handler) Details(c *gin.Context) { pv, status := h.problemService.QueryLatestVersion(req.Pid) if status != e.Success { e.Pong(c, status, nil) + return } e.Pong(c, e.Success, gin.H{ "problem": p, diff --git a/internal/api/status/queryByVersion.go b/internal/api/status/queryByVersion.go index 3a738c0..8d61507 100644 --- a/internal/api/status/queryByVersion.go +++ b/internal/api/status/queryByVersion.go @@ -19,7 +19,7 @@ type queryByVersionRequest struct { // @Accept application/x-www-form-urlencoded // @Produce json // @Param pvid formData uint true "problem version id" -// @Param offset formData int true "start position" +// @Param offset formData int false "start position" // @Param limit formData int true "limit number of records" // @Response 200 {object} e.Response "[]*model.status" // @Router /v1/status/query/problem_version [post] diff --git a/internal/api/submission/query.go b/internal/api/submission/query.go index e3e6126..53bf3fa 100644 --- a/internal/api/submission/query.go +++ b/internal/api/submission/query.go @@ -23,13 +23,12 @@ type queryResponse struct { // @Description Query submissions // @Accept application/x-www-form-urlencoded // @Produce json -// @Param pid formData uint true "problem id" -// @Param uid formData uint true "user id" -// @Param offset formData int true "start position" +// @Param pid formData uint false "problem id" +// @Param uid formData uint false "user id" +// @Param offset formData int false "start position" // @Param limit formData int true "limit number of records" // @Response 200 {object} e.Response "queryResponse" // @Router /v1/submission/query [post] - func (h *handler) Query(c *gin.Context) { req := new(queryRequest) diff --git a/resource/bench/bench.py b/resource/bench/bench.py new file mode 100644 index 0000000..08a3255 --- /dev/null +++ b/resource/bench/bench.py @@ -0,0 +1,70 @@ +import random +import string + +from locust import HttpUser, task + + +def randomstring(length): + return ''.join(random.choice(string.ascii_letters) for i in range(length)) + + +class WOJUser(HttpUser): + + def on_start(self): + self.username = randomstring(16) + self.nickname = randomstring(16) + self.password = randomstring(16) + + with self.client.post("/api/v1/user/create", data={ + "username": self.username, + "nickname": self.nickname, + "password": self.password + }) as resp: + j = resp.json() + if j["code"] != 0: + resp.failure("create user failed") + else: + self.token = j["body"] + + @task + def view_problem(self): + pid = [] + + with self.client.post("/api/v1/problem/search") as resp: + j = resp.json() + if j["code"] != 0: + resp.failure("search problem failed") + else: + for p in j["body"]: + pid.append(p["meta"]["ID"]) + + for p in pid: + with self.client.post("/api/v1/problem/details", data={"pid": pid}) as resp: + if resp.json()["code"] != 0: + resp.failure("view problem failed") + + @task + def submit_code(self): + code = """ + #include + using namespace std; + int main() { + int a, b; + cin >> a >> b; + cout << a + b; + return 0; + } + """ + + with self.client.post("/api/v1/submission/create", + headers={"Authorization": "Bearer " + self.token}, + data={"pid": 5, "language": "cpp", "code": code} + ) as resp: + if resp.json()["code"] != 0: + resp.failure("submit code failed") + + @task + def view_submission(self): + with self.client.post("/api/v1/submission/query", data={"pid": 5, "limit": 100}) as resp: + if resp.json()["code"] != 0: + resp.failure("view submission failed") diff --git a/resource/frontend/.gitignore b/resource/frontend/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/resource/runner/scripts/run_timeout.sh b/resource/runner/scripts/run_timeout.sh index a55fe72..1f48957 100755 --- a/resource/runner/scripts/run_timeout.sh +++ b/resource/runner/scripts/run_timeout.sh @@ -5,7 +5,7 @@ function docker_run() { local timeout=${TIMEOUT:-10} local log_file=${LOG_FILE:-"/dev/stderr"} - local log_limit=${LOG_LIMIT:-1K} + local log_limit=${LOG_LIMIT:-4K} log_info "$DOCKER run with timeout $timeout" CONTAINER_NAME=$(uuidgen) ( @@ -15,4 +15,5 @@ function docker_run() { $DOCKER run --rm --name "$CONTAINER_NAME" "$@" 2>&1 | head -c "$log_limit" >"$log_file" pkill -P $$ $DOCKER kill "$CONTAINER_NAME" >/dev/null 2>&1 + return 0 }