Skip to content

Commit 942e01b

Browse files
authored
Merge pull request open-lambda#120 from open-lambda/testing2
use pandas tests inside SOCK containers as OL tests
2 parents 0e97037 + fafdc66 commit 942e01b

File tree

4 files changed

+120
-6
lines changed

4 files changed

+120
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ check-fmt:
9191
cd bin-functions && cargo fmt --check
9292

9393
lint:
94-
pylint scripts --ignore=build --disable=missing-docstring,multiple-imports,global-statement,invalid-name,W0511,W1510
94+
pylint scripts --ignore=build --disable=missing-docstring,multiple-imports,global-statement,invalid-name,W0511,W1510,R0801
9595
cd wasm-worker && cargo clippy
9696
cd bin-functions && cargo clippy
9797

scripts/helper/test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ def _wrapper(*args, **kwargs):
100100
mounts0 = mounts()
101101
worker = None
102102

103-
try:
104-
worker = WORKER_TYPE()
105-
print("Worker started")
106-
except Exception as err:
107-
print(f"Failed to start worker: {err}")
103+
worker = WORKER_TYPE()
104+
assert worker
105+
print("Worker started")
108106

109107
if worker:
110108
try:

scripts/package_tests.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#! /bin/env python3
2+
3+
'''Many popular PyPI packages (e.g., pandas, scikit-learn, etc) have
4+
extensive tests. We want those packages to work on OL, so we run
5+
these inside the SOCK containers. Some of these suites take quite
6+
long (e.g., 20+ minutes), so we set large timeouts. Very high memory
7+
limits (>1GB) are also necessary.
8+
'''
9+
10+
import argparse
11+
import os
12+
13+
from helper import DockerWorker, SockWorker, prepare_open_lambda, setup_config
14+
from helper import TestConfContext, assert_eq
15+
16+
from helper.test import set_test_filter, start_tests, check_test_results, set_worker_type, test
17+
18+
from open_lambda import OpenLambda
19+
20+
# These will be set by argparse in main()
21+
OL_DIR = None
22+
23+
@test
24+
def pandas_test():
25+
open_lambda = OpenLambda()
26+
result = open_lambda.run("pandas-tests", None)
27+
assert_eq(result, True)
28+
29+
def run_tests():
30+
with TestConfContext(mem_pool_mb=6000, limits={"mem_mb": 2000, "max_runtime_default": 3600}):
31+
pandas_test()
32+
33+
def main():
34+
global OL_DIR
35+
36+
parser = argparse.ArgumentParser(description='Run tests for OpenLambda')
37+
parser.add_argument('--reuse_config', action="store_true")
38+
parser.add_argument('--worker_type', type=str, default="sock")
39+
parser.add_argument('--test_filter', type=str, default="")
40+
parser.add_argument('--registry', type=str, default="test-registry")
41+
parser.add_argument('--ol_dir', type=str, default="test-dir")
42+
43+
args = parser.parse_args()
44+
45+
set_test_filter([name for name in args.test_filter.split(",") if name != ''])
46+
OL_DIR = args.ol_dir
47+
48+
setup_config(args.ol_dir)
49+
prepare_open_lambda(args.ol_dir)
50+
51+
trace_config = {
52+
"cgroups": True,
53+
"memory": True,
54+
"evictor": True,
55+
"package": True,
56+
}
57+
with TestConfContext(registry=os.path.abspath(args.registry), trace=trace_config):
58+
if args.worker_type == 'docker':
59+
set_worker_type(DockerWorker)
60+
elif args.worker_type == 'sock':
61+
set_worker_type(SockWorker)
62+
else:
63+
raise RuntimeError(f"Invalid worker type {args.worker_type}")
64+
65+
start_tests()
66+
run_tests()
67+
68+
check_test_results()
69+
70+
if __name__ == '__main__':
71+
main()

test-registry/pandas-tests/f.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ol-install: pandas,pytest,hypothesis,exceptiongroup
2+
# TODO: why isn't exceptiongroup automatically installed?
3+
4+
import numpy
5+
import pandas
6+
import pytest
7+
import inspect
8+
import os, sys
9+
import subprocess
10+
import time
11+
12+
def f(event):
13+
print("redirecting to stdout.txt, stderr.txt")
14+
sys.stdout.close()
15+
sys.stderr.close()
16+
sys.stdout = open("/tmp/stdout.txt", 'w', 1)
17+
sys.stderr = open("/tmp/stderr.txt", 'w', 1)
18+
19+
pkg = os.path.dirname(pandas.__file__)
20+
print(pkg)
21+
22+
# TODO: look into these to determine whether it's a problem
23+
tests_that_fail = [
24+
"test_oo_optimizable",
25+
"test_oo_optimized_datetime_index_unpickle",
26+
"test_missing_required_dependency",
27+
"test_util_in_top_level",
28+
"test_raw_roundtrip",
29+
"test_get_handle_with_path",
30+
"test_with_missing_lzma",
31+
"test_with_missing_lzma_runtime",
32+
"test_multi_thread_string_io_read_csv",
33+
"test_multi_thread_path_multipart_read_csv",
34+
"test_server_and_default_headers",
35+
"test_server_and_custom_headers",
36+
"test_server_and_all_custom_headers",
37+
"TestS3",
38+
"s3",
39+
]
40+
41+
cmd = [pkg, "-o", "cache_dir=/tmp/.my_cache_dir", "-m", "(not slow)"]
42+
cmd.extend(["-k", " and ".join([f"(not {name})" for name in tests_that_fail])])
43+
print(" ".join(cmd))
44+
result = pytest.main(cmd)
45+
return result == pytest.ExitCode.OK

0 commit comments

Comments
 (0)