Skip to content

Commit 18a3b36

Browse files
committed
unit tests
1 parent 88a370b commit 18a3b36

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

__tests__/code-excution/python.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ describe("Python transform into executable", () => {
77
const worker = new JobWorker();
88
it('should instantiate an object and execute the function', () => {
99
const functionName = "solution"
10-
const code = worker.transformCodeIntoExecutable("python3", {
10+
const codeContext = worker.transformCodeIntoExecutable("python3", {
1111
code: "",
1212
functionName: functionName
1313
})
14-
expect(code).toBe(`\nprint(${mainClassName}().${functionName}())`)
14+
expect(codeContext).toBe(`\nprint(${mainClassName}().${functionName}())`)
1515
})
1616
})
1717

__tests__/worker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { mainClassName } from "../src/config";
2-
import { CodeContext, ContainerInitialization } from "../src/types/worker";
1+
import { ContainerInitialization } from "../src/types/worker";
32
import JobWorker from "../src/worker";
43

54

dockerfiles/python3.Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
FROM python:3.8-slim-buster
22
WORKDIR /src
3-
# COPY ./test.py /src
43
CMD ["python3", "target.py"]

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export const mainClassName = "Execute"
2+
export const containerMemLimit = "--memory=100M"
3+
export const containerCPULimit = "--cpus=0.1"

src/worker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ExecuteContainer,
1313
Stdout,
1414
} from "./types/worker";
15-
import { mainClassName } from "./config";
15+
import { containerCPULimit, containerMemLimit, mainClassName } from "./config";
1616

1717
class JobWorker {
1818
constructor() {}
@@ -28,7 +28,7 @@ class JobWorker {
2828
*/
2929
createContainer(language: language): Promise<ContainerInitialization> {
3030
return new Promise((resolve, reject) => {
31-
const initCommand = `docker create ${language}`;
31+
const initCommand = `docker create ${containerMemLimit} ${containerCPULimit} ${language}`;
3232
if (!(language in this._fileFormats)) {
3333
return reject({
3434
error: true,
@@ -103,7 +103,7 @@ class JobWorker {
103103
/**
104104
* Removes a container with the provided containerID
105105
*/
106-
removeContainer(containerID: string): Promise<Stdout> {
106+
async removeContainer(containerID: string): Promise<Stdout> {
107107
return new Promise((resolve, reject) => {
108108
const removeContainer = `docker rm --force ${containerID}`;
109109
child.exec(removeContainer, (error, stdout, stderr) => {

0 commit comments

Comments
 (0)