Skip to content

Commit

Permalink
fix(iris): handle-runtime-error-when-realtime-exceeded
Browse files Browse the repository at this point in the history
* fix(iris): not throw RuntimeError when RealTime exceeded 2000ms

* feat(iris): customizing sandbox result to codedang logic

* fix(iris): commented logic applied

* fix(iris): apply segment-fault-err on router

* fix(iris): modify sandbox result code handling

* fix(iris): modify loging message

* fix(be): add judge result status segmentation-fault

* fix(be): modify testcase

---------

Co-authored-by: jspark2000 <[email protected]>
  • Loading branch information
goathoon and jspark2000 authored Aug 20, 2024
1 parent 1127b1c commit 2e8aff6
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class JudgeResult {
}

export class JudgerResponse {
@Max(8)
@Max(9)
@Min(0)
@IsNotEmpty()
resultCode: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ describe('SubmissionSubscriptionService', () => {
).to.be.true
})

it('should call handleJudgeError when CompileError or ServerError detected', async () => {
it('should call handleJudgeError when ServerError detected', async () => {
const handlerSpy = sandbox.stub(service, 'handleJudgeError').resolves()

const updateSpy = sandbox
.stub(service, 'updateTestcaseJudgeResult')
.resolves()
const serverErrMsg = {
resultCode: 8,
resultCode: 9,
submissionId: 1,
error: '',
judgeResult
Expand All @@ -189,6 +191,25 @@ describe('SubmissionSubscriptionService', () => {
await service.handleJudgerMessage(serverErrMsg)
expect(handlerSpy.calledOnceWith(ResultStatus.ServerError, serverErrMsg))
.to.be.true
expect(updateSpy.notCalled).to.be.true
})

it('should call handleJudgeError when CompileError detected', async () => {
const handlerSpy = sandbox.stub(service, 'handleJudgeError').resolves()
const updateSpy = sandbox
.stub(service, 'updateTestcaseJudgeResult')
.resolves()
const serverErrMsg = {
resultCode: 6,
submissionId: 1,
error: '',
judgeResult
}

await service.handleJudgerMessage(serverErrMsg)
expect(handlerSpy.calledOnceWith(ResultStatus.CompileError, serverErrMsg))
.to.be.true
expect(updateSpy.notCalled).to.be.true
})
})

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/libs/constants/src/submission.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const Status = (code: number) => {
return ResultStatus.CompileError
case 7: // TESTCASE_ERROR
return ResultStatus.ServerError
case 8: // SERVER_ERROR
return ResultStatus.ServerError
case 8: // Segmentation Fault
return ResultStatus.SegmentationFaultError
default:
return ResultStatus.ServerError
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "ResultStatus" ADD VALUE 'SegmentationFaultError';
3 changes: 2 additions & 1 deletion apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ model Problem {
/// "locked": boolean
/// }[]
/// }
template Json[] @default([])
languages Language[]
timeLimit Int @map("time_limit") // unit: MilliSeconds
Expand Down Expand Up @@ -435,6 +435,7 @@ enum ResultStatus {
MemoryLimitExceeded
OutputLimitExceeded
ServerError
SegmentationFaultError
}

model CodeDraft {
Expand Down
1 change: 1 addition & 0 deletions apps/iris/src/handler/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ var (
ErrRealTimeLimitExceed = errors.New("realtime limit exceeded")
ErrMemoryLimitExceed = errors.New("memory limit exceeded")
ErrRuntime = errors.New("runtime error")
ErrSegFault = errors.New("segmentation fault")
)
20 changes: 10 additions & 10 deletions apps/iris/src/handler/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,20 @@ func SandboxResultCodeToJudgeResultCode(code sandbox.ResultCode) JudgeResultCode

func ParseError(j JudgeResult) error {
if j.ResultCode != ACCEPTED {
return resultCodeToError(j.ResultCode)
}
return nil
}

func ParseFirstError(j []JudgeResult) error {
for _, res := range j {
if res.ResultCode != ACCEPTED {
return resultCodeToError(res.ResultCode)
// TODO : Customizing Results
if j.Signal == 11 && j.ResultCode != MEMORY_LIMIT_EXCEEDED {
return resultCodeToError(SEGMENATION_FAULT)
}
if j.RealTime >= 2000 && j.Signal == 9 && j.ResultCode == RUNTIME_ERROR {
return resultCodeToError(REAL_TIME_LIMIT_EXCEEDED)
}
return resultCodeToError(j.ResultCode)
}
return nil
}

func resultCodeToError(code JudgeResultCode) error {
caller := "parse first error"
caller := "parse error"
err := &HandlerError{
caller: caller,
level: logger.INFO,
Expand All @@ -64,6 +62,8 @@ func resultCodeToError(code JudgeResultCode) error {
return err.Wrap(ErrMemoryLimitExceed)
case RUNTIME_ERROR:
return err.Wrap(ErrRuntime)
case SEGMENATION_FAULT:
return err.Wrap(ErrSegFault)
}
return &HandlerError{caller: caller, err: ErrSandbox, level: logger.ERROR}
}
3 changes: 2 additions & 1 deletion apps/iris/src/handler/judge-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const (
MEMORY_LIMIT_EXCEEDED
RUNTIME_ERROR
SYSTEM_ERROR
SEGMENATION_FAULT
)

type JudgeHandler struct {
Expand Down Expand Up @@ -338,7 +339,7 @@ func (j *JudgeHandler) judgeTestcase(idx int, dir string, validReq *Request,
res.SetJudgeExecResult(runResult.ExecResult)

if runResult.ExecResult.ResultCode != sandbox.RUN_SUCCESS {
res.SetJudgeResultCode(JudgeResultCode(runResult.ExecResult.ResultCode))
res.SetJudgeResultCode(SandboxResultCodeToJudgeResultCode(runResult.ExecResult.ResultCode))
goto Send
}

Expand Down
4 changes: 4 additions & 0 deletions apps/iris/src/router/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
RUNTIME_ERROR
COMPILE_ERROR
TESTCASE_ERROR
SEGMENTATION_FAULT_ERROR
SERVER_ERROR
)

Expand Down Expand Up @@ -96,5 +97,8 @@ func ErrorToResultCode(err error) ResultCode {
if errors.Is(err, handler.ErrTestcaseGet) {
return TESTCASE_ERROR
}
if errors.Is(err, handler.ErrSegFault) {
return SEGMENTATION_FAULT_ERROR
}
return SERVER_ERROR
}

0 comments on commit 2e8aff6

Please sign in to comment.