mirror of
https://github.com/GaloisInc/cryptol.git
synced 2025-01-05 23:17:42 +03:00
rpc/fix: tweak tests for docker/http to not hang (#1294)
This commit is contained in:
parent
e161b0f6e2
commit
7a68739d0d
@ -3,6 +3,7 @@ from argo_client.interaction import ArgoException
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import unittest
|
import unittest
|
||||||
import io
|
import io
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import cryptol
|
import cryptol
|
||||||
import cryptol.cryptoltypes
|
import cryptol.cryptoltypes
|
||||||
@ -21,7 +22,7 @@ class BasicServerTests(unittest.TestCase):
|
|||||||
self.c = cryptol.connect(verify=False)
|
self.c = cryptol.connect(verify=False)
|
||||||
|
|
||||||
def test_extend_search_path(self):
|
def test_extend_search_path(self):
|
||||||
"""Test that extending the search path acts as expected w.r.t. loads."""
|
# Test that extending the search path acts as expected w.r.t. loads
|
||||||
c = self.c
|
c = self.c
|
||||||
|
|
||||||
c.extend_search_path(str(Path('tests','cryptol','test-files', 'test-subdir')))
|
c.extend_search_path(str(Path('tests','cryptol','test-files', 'test-subdir')))
|
||||||
@ -68,15 +69,43 @@ class BasicServerTests(unittest.TestCase):
|
|||||||
self.assertLess(t2 - t1, 5)
|
self.assertLess(t2 - t1, 5)
|
||||||
|
|
||||||
def test_interrupt(self):
|
def test_interrupt(self):
|
||||||
c = self.c
|
# Check if this test is using a local server, if not we assume it's a remote HTTP server
|
||||||
c.load_file(str(Path('tests','cryptol','test-files', 'examples','AES.cry')))
|
if os.getenv('CRYPTOL_SERVER') is not None:
|
||||||
|
c = self.c
|
||||||
|
c.load_file(str(Path('tests','cryptol','test-files', 'examples','AES.cry')))
|
||||||
|
|
||||||
|
t1 = time.time()
|
||||||
|
c.check("\\(bv : [256]) -> ~ (~ (~ (~bv))) == bv", num_tests="all", timeout=30.0)
|
||||||
|
# ^ .result() intentionally omitted so we don't wait on it's result and we can interrupt
|
||||||
|
# it on the next line. We add a timeout just in case to the test fails
|
||||||
|
time.sleep(.5)
|
||||||
|
c.interrupt()
|
||||||
|
self.assertTrue(c.safe("aesEncrypt").result())
|
||||||
|
t2 = time.time()
|
||||||
|
self.assertLess(t2 - t1, 15.0) # ensure th interrupt ended things and not the timeout
|
||||||
|
elif os.getenv('CRYPTOL_SERVER_URL') is not None:
|
||||||
|
c = self.c
|
||||||
|
other_c = cryptol.connect(verify=False)
|
||||||
|
# Since this is the HTTP server, due to client implementation details
|
||||||
|
# the requests don't return until they get a response, so we fork
|
||||||
|
# to interrupt the server
|
||||||
|
newpid = os.fork()
|
||||||
|
if newpid == 0:
|
||||||
|
time.sleep(5)
|
||||||
|
other_c.interrupt()
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
|
c.load_file(str(Path('tests','cryptol','test-files', 'examples','AES.cry')))
|
||||||
|
|
||||||
|
t1 = time.time()
|
||||||
|
c.check("\\(bv : [256]) -> ~ (~ (~ (~bv))) == bv", num_tests="all", timeout=60.0)
|
||||||
|
self.assertTrue(c.safe("aesEncrypt").result())
|
||||||
|
t2 = time.time()
|
||||||
|
self.assertLess(t2 - t1, 20.0) # ensure th interrupt ended things and not the timeout
|
||||||
|
else:
|
||||||
|
# Otherwise fail... since this shouldn't be possible
|
||||||
|
self.assertFalse("Impossible")
|
||||||
|
|
||||||
c.check("\\(bv : [256]) -> ~ (~ (~ (~bv))) == bv", num_tests="all")
|
|
||||||
# ^ .result() intentionally omitted so we don't wait on it's result and we can interrupt
|
|
||||||
# it on the next line.
|
|
||||||
time.sleep(.5)
|
|
||||||
c.interrupt()
|
|
||||||
self.assertTrue(c.safe("aesEncrypt").result())
|
|
||||||
|
|
||||||
def test_prove_timeout(self):
|
def test_prove_timeout(self):
|
||||||
c = self.c
|
c = self.c
|
||||||
|
@ -31,10 +31,10 @@ run_test poetry run mypy cryptol/ tests/
|
|||||||
|
|
||||||
get_server cryptol-remote-api
|
get_server cryptol-remote-api
|
||||||
echo "Running cryptol-remote-api tests..."
|
echo "Running cryptol-remote-api tests..."
|
||||||
run_test poetry run python -m unittest discover tests/cryptol
|
run_test poetry run python -m unittest discover --verbose tests/cryptol
|
||||||
|
|
||||||
get_server cryptol-eval-server
|
get_server cryptol-eval-server
|
||||||
echo "Running cryptol-eval-server tests..."
|
echo "Running cryptol-eval-server tests..."
|
||||||
run_test poetry run python -m unittest discover tests/cryptol_eval
|
run_test poetry run python -m unittest discover --verbose tests/cryptol_eval
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
|
||||||
PROTO=${1:-"http"}
|
PROTO=${1:-"http"}
|
||||||
@ -25,10 +27,13 @@ pushd $DIR/python
|
|||||||
NUM_FAILS=0
|
NUM_FAILS=0
|
||||||
|
|
||||||
echo "Setting up python environment for remote server clients..."
|
echo "Setting up python environment for remote server clients..."
|
||||||
|
poetry update
|
||||||
poetry install
|
poetry install
|
||||||
|
|
||||||
export CRYPTOL_SERVER_URL="$PROTO://localhost:8080/"
|
export CRYPTOL_SERVER_URL="$PROTO://localhost:8080/"
|
||||||
poetry run python -m unittest discover tests/cryptol
|
|
||||||
|
echo "Running cryptol-remote-api tests with remote server at $CRYPTOL_SERVER_URL..."
|
||||||
|
poetry run python -m unittest discover --verbose tests/cryptol
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
NUM_FAILS=$(($NUM_FAILS+1))
|
NUM_FAILS=$(($NUM_FAILS+1))
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user