2020-01-21 10:01:55 -05:00
|
|
|
# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-05-30 16:40:40 -04:00
|
|
|
import os
|
2019-05-27 09:27:55 -04:00
|
|
|
|
2019-06-03 12:35:55 -04:00
|
|
|
from test_util import DenoTestCase, run_tests
|
2019-09-10 11:09:54 -04:00
|
|
|
from util import (parse_exit_code, shell_quote_win, parse_wrk_output,
|
|
|
|
root_path)
|
2018-08-10 13:38:32 -04:00
|
|
|
|
|
|
|
|
2019-05-30 16:40:40 -04:00
|
|
|
class TestUtil(DenoTestCase):
|
2019-05-27 09:27:55 -04:00
|
|
|
def test_parse_exit_code(self):
|
2019-09-11 16:47:42 -04:00
|
|
|
assert parse_exit_code('hello_error54_world') == 54
|
|
|
|
assert parse_exit_code('hello_error_world') == 1
|
|
|
|
assert parse_exit_code('hello_world') == 0
|
2019-05-27 09:27:55 -04:00
|
|
|
|
|
|
|
def test_shell_quote_win(self):
|
2019-09-11 16:47:42 -04:00
|
|
|
assert shell_quote_win('simple') == 'simple'
|
|
|
|
assert shell_quote_win(
|
|
|
|
'roof/\\isoprojection') == 'roof/\\isoprojection'
|
|
|
|
assert shell_quote_win('with space') == '"with space"'
|
|
|
|
assert shell_quote_win('embedded"quote') == '"embedded""quote"'
|
|
|
|
assert shell_quote_win(
|
|
|
|
'a"b""c\\d\\"e\\\\') == '"a""b""""c\\d\\\\""e\\\\\\\\"'
|
2019-05-27 09:27:55 -04:00
|
|
|
|
|
|
|
def test_parse_wrk_output(self):
|
|
|
|
f = open(os.path.join(root_path, "tools/testdata/wrk1.txt"))
|
|
|
|
stats = parse_wrk_output(f.read())
|
|
|
|
assert stats['req_per_sec'] == 1837
|
2019-07-28 17:31:18 -04:00
|
|
|
assert stats['max_latency'] == 6.25
|
2019-05-27 09:27:55 -04:00
|
|
|
|
|
|
|
f2 = open(os.path.join(root_path, "tools/testdata/wrk2.txt"))
|
|
|
|
stats2 = parse_wrk_output(f2.read())
|
|
|
|
assert stats2['req_per_sec'] == 53435
|
2019-07-28 17:31:18 -04:00
|
|
|
assert stats2['max_latency'] == 6.22
|
2019-05-27 09:27:55 -04:00
|
|
|
|
|
|
|
f3 = open(os.path.join(root_path, "tools/testdata/wrk3.txt"))
|
|
|
|
stats3 = parse_wrk_output(f3.read())
|
|
|
|
assert stats3['req_per_sec'] == 96037
|
2019-07-28 17:31:18 -04:00
|
|
|
assert stats3['max_latency'] == 6.36
|
2018-10-15 16:44:35 -04:00
|
|
|
|
2020-05-06 16:34:48 -04:00
|
|
|
def test_executable_exists(self):
|
|
|
|
assert os.path.exists(self.deno_exe)
|
|
|
|
|
2018-10-15 16:44:35 -04:00
|
|
|
|
2018-08-19 03:00:34 -04:00
|
|
|
if __name__ == '__main__':
|
2019-06-03 12:35:55 -04:00
|
|
|
run_tests()
|