From 6e726ad40b3e5b1e07c1b474a65c23a30262edac Mon Sep 17 00:00:00 2001 From: thevindu-w Date: Tue, 8 Aug 2023 11:31:39 +0530 Subject: [PATCH 1/2] Modify tests to fail and exit on different response without timeout --- Dockerfile | 13 ++++++++++++- test-docker.sh | 2 +- tests/integration/test.py | 30 ++++++++++++++++-------------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9aec71981..2255a068f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,13 +34,24 @@ RUN make install ENV HOME="/home/ubuntu" ENV JASMINEGRAPH_HOME="/home/ubuntu/software/jasminegraph" + RUN mkdir /home/ubuntu/software/jasminegraph WORKDIR /home/ubuntu/software/jasminegraph + RUN pip install tensorflow==2.5.3 RUN pip install -U scikit-learn -COPY . . +COPY ./GraphSAGE ./GraphSAGE RUN pip install -r ./GraphSAGE/requirements +COPY ./conf ./conf +COPY ./src ./src +COPY ./src_python ./src_python +COPY ./build.sh ./build.sh +COPY ./CMakeLists.txt ./CMakeLists.txt +COPY ./main.cpp ./main.cpp +COPY ./main.h ./main.h +COPY ./run-docker.sh ./run-docker.sh + RUN sh build.sh ENTRYPOINT ["/home/ubuntu/software/jasminegraph/run-docker.sh"] CMD ["bash"] \ No newline at end of file diff --git a/test-docker.sh b/test-docker.sh index edd0c0597..7f36a8b33 100755 --- a/test-docker.sh +++ b/test-docker.sh @@ -28,7 +28,7 @@ while ! nc -zvn 127.0.0.1 7777 &>/dev/null; do sleep .2 done -timeout 1800 python3 -u tests/integration/test.py |& tee "logs/${run_id}_test.txt" +timeout 600 python3 -u tests/integration/test.py |& tee "logs/${run_id}_test.txt" exit_code="${PIPESTATUS[0]}" rm -rf tests/integration/env stop_and_remove_containers diff --git a/tests/integration/test.py b/tests/integration/test.py index 8fd77ea62..1a79803ef 100644 --- a/tests/integration/test.py +++ b/tests/integration/test.py @@ -32,24 +32,26 @@ DONE=b'done' LINE_END=b'\r\n' -def recv_all(sock, n_bytes): +def expect_response(sock, expected): + global passedAll buffer = bytearray() read = 0 - while read < n_bytes: - received = sock.recv(n_bytes - read) + expected_len = len(expected) + while read < expected_len: + received = sock.recv(expected_len - read) + received_len = len(received) if received: - read += len(received) + if received != expected[read:read + received_len]: + buffer.extend(received) + data = bytes(buffer) + logging.warning(f'Output mismatch\nexpected : {expected}\nreceived : {data}') + passedAll = False + return False + read += received_len buffer.extend(received) - return bytes(buffer) - -def expect_response(sock, expected): - global passedAll - data = recv_all(sock, len(expected)) + data = bytes(buffer) print(data.decode('utf-8'), end='') - if data != expected: - logging.warning(f'Output mismatch\nexpected : {expected}\nreceived : {data}') - passedAll = False - return False + assert data == expected return True def send_and_expect_response(sock, testName, send, expected, exitOnFail=False): @@ -60,7 +62,7 @@ def send_and_expect_response(sock, testName, send, expected, exitOnFail=False): failedTests.append(testName) if exitOnFail: print() - logging.fatal('Failed some tests,', file=sys.stderr) + logging.fatal('Failed some tests,') print(*failedTests, sep='\n', file=sys.stderr) sys.exit(1) From 84fc70245e9bc2ddcce496672c0089180ecd1a07 Mon Sep 17 00:00:00 2001 From: thevindu-w Date: Tue, 8 Aug 2023 12:01:21 +0530 Subject: [PATCH 2/2] Moved timeout value to TIMEOUT_SECONDS variable --- test-docker.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test-docker.sh b/test-docker.sh index 7f36a8b33..639a55e6e 100755 --- a/test-docker.sh +++ b/test-docker.sh @@ -1,10 +1,11 @@ #!/bin/bash PROJECT_ROOT="$(pwd)" -mkdir -p logs/ - +TIMEOUT_SECONDS=600 run_id="$(date +%y%m%d_%H%M%S)" +mkdir -p logs/ + stop_and_remove_containers () { docker ps -q | xargs docker kill &>/dev/null docker container prune -f &>/dev/null @@ -28,7 +29,7 @@ while ! nc -zvn 127.0.0.1 7777 &>/dev/null; do sleep .2 done -timeout 600 python3 -u tests/integration/test.py |& tee "logs/${run_id}_test.txt" +timeout "${TIMEOUT_SECONDS}" python3 -u tests/integration/test.py |& tee "logs/${run_id}_test.txt" exit_code="${PIPESTATUS[0]}" rm -rf tests/integration/env stop_and_remove_containers