Skip to content

Commit

Permalink
feat(iris): pass run output when test submission (#2137)
Browse files Browse the repository at this point in the history
* feat: pass run output when test submission

* chore: remove typo

* feat: add output property on run result cache object

* fix: test code
  • Loading branch information
jspark2000 authored Oct 4, 2024
1 parent 49894bc commit d85d1e4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class JudgeResult {
signal: number
exitCode: number
errorCode: number
output?: string
}

export class JudgerResponse {
Expand Down
18 changes: 18 additions & 0 deletions apps/backend/apps/client/src/submission/submission-sub.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,42 @@ export class SubmissionSubscriptionService implements OnModuleInit {
const key = testKey(userId)
const status = Status(msg.resultCode)
const testcaseId = msg.judgeResult?.testcaseId
const output = this.parseError(msg, status)

const testcases =
(await this.cacheManager.get<
{
id: number
result: ResultStatus
output?: string
}[]
>(key)) ?? []

testcases.forEach((tc) => {
if (!testcaseId || tc.id === testcaseId) {
tc.result = status
tc.output = output
}
})

await this.cacheManager.set(key, testcases, TEST_SUBMISSION_EXPIRE_TIME)
}

parseError(msg: JudgerResponse, status: ResultStatus): string {
if (msg.judgeResult?.output) return msg.judgeResult.output

switch (status) {
case ResultStatus.CompileError:
return msg.error ?? ''
case ResultStatus.SegmentationFaultError:
return 'Segmentation Fault'
case ResultStatus.RuntimeError:
return 'Value Error'
default:
return ''
}
}

async validateJudgerResponse(msg: object): Promise<JudgerResponse> {
const res: JudgerResponse = plainToInstance(JudgerResponse, msg)
await validateOrReject(res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export class SubmissionService {
{
id: number
result: ResultStatus
output?: string
}[]
>(key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const judgeResult = {
memory: 10000000,
signal: 0,
exitCode: 0,
errorCode: 0
errorCode: 0,
output: undefined
}

const msg = {
Expand Down
2 changes: 2 additions & 0 deletions apps/iris/src/handler/judge-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (r Request) Validate() (*Request, error) {
type JudgeResult struct {
TestcaseId int `json:"testcaseId"`
ResultCode JudgeResultCode `json:"resultCode"`
Output string `json:"output"`
CpuTime int `json:"cpuTime"`
RealTime int `json:"realTime"`
Memory int `json:"memory"`
Expand Down Expand Up @@ -339,6 +340,7 @@ func (j *JudgeHandler) judgeTestcase(idx int, dir string, validReq *Request,

res.TestcaseId = tc.Id
res.SetJudgeExecResult(runResult.ExecResult)
res.Output = string(runResult.Output)

if runResult.ExecResult.ResultCode != sandbox.RUN_SUCCESS {
res.SetJudgeResultCode(SandboxResultCodeToJudgeResultCode(runResult.ExecResult.ResultCode))
Expand Down

0 comments on commit d85d1e4

Please sign in to comment.