mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Add integration test
This commit is contained in:
parent
d9bb3ef91b
commit
4ef322274d
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,6 +12,7 @@
|
||||
/build
|
||||
/build_*
|
||||
/build-*
|
||||
/tests/venv
|
||||
|
||||
/docs/build
|
||||
/docs/publish
|
||||
|
@ -42,6 +42,12 @@
|
||||
-->
|
||||
</logger>
|
||||
|
||||
<send_crash_reports>
|
||||
<!-- Changing <enabled> to true allows sending crash reports to ClickHouse core developers team -->
|
||||
<!-- Doing so at least in pre-production environments is highly appreciated -->
|
||||
<enabled>false</enabled>
|
||||
</send_crash_reports>
|
||||
|
||||
<!--display_name>production</display_name--> <!-- It is the name that will be shown in the client -->
|
||||
<http_port>8123</http_port>
|
||||
<tcp_port>9000</tcp_port>
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<yandex>
|
||||
<send_crash_reports>
|
||||
<enabled>true</enabled>
|
||||
<debug>true</debug>
|
||||
<endpoint>http://6f33034cfe684dd7a3ab9875e57b1c8d@localhost:9500/5226277</endpoint>
|
||||
</send_crash_reports>
|
||||
</yandex>
|
43
tests/integration/test_send_crash_reports/http_server.py
Normal file
43
tests/integration/test_send_crash_reports/http_server.py
Normal file
@ -0,0 +1,43 @@
|
||||
import BaseHTTPServer
|
||||
|
||||
RESULT_PATH = '/result.txt'
|
||||
|
||||
class SentryHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
post_data = self.__read_and_decode_post_data()
|
||||
with open(RESULT_PATH, 'w') as f:
|
||||
if self.headers.get("content-type") != "application/x-sentry-envelope":
|
||||
f.write("INCORRECT_CONTENT_TYPE")
|
||||
elif self.headers.get("content-length") < 3000:
|
||||
f.write("INCORRECT_CONTENT_LENGTH")
|
||||
elif '"http://6f33034cfe684dd7a3ab9875e57b1c8d@localhost:9500/5226277"' not in post_data:
|
||||
f.write('INCORRECT_POST_DATA')
|
||||
else:
|
||||
f.write("OK")
|
||||
self.send_response(200)
|
||||
|
||||
def __read_and_decode_post_data(self):
|
||||
transfer_encoding = self.headers.get("transfer-Encoding")
|
||||
decoded = ""
|
||||
if transfer_encoding == "chunked":
|
||||
while True:
|
||||
s = self.rfile.readline()
|
||||
chunk_length = int(s, 16)
|
||||
if not chunk_length:
|
||||
break
|
||||
decoded += self.rfile.read(chunk_length)
|
||||
self.rfile.readline()
|
||||
else:
|
||||
content_length = int(self.headers.get("content-length", 0))
|
||||
decoded = self.rfile.read(content_length)
|
||||
return decoded
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open(RESULT_PATH, 'w') as f:
|
||||
f.write("INITIAL_STATE")
|
||||
httpd = BaseHTTPServer.HTTPServer(("localhost", 9500,), SentryHandler)
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
finally:
|
||||
httpd.server_close()
|
44
tests/integration/test_send_crash_reports/test.py
Normal file
44
tests/integration/test_send_crash_reports/test.py
Normal file
@ -0,0 +1,44 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
import helpers.cluster
|
||||
import helpers.test_tools
|
||||
import http_server
|
||||
|
||||
|
||||
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def started_node():
|
||||
cluster = helpers.cluster.ClickHouseCluster(__file__)
|
||||
try:
|
||||
node = cluster.add_instance("node", main_configs=[
|
||||
os.path.join(SCRIPT_DIR, "configs", "config_send_crash_reports.xml")
|
||||
])
|
||||
cluster.start()
|
||||
yield node
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
def test_send_segfault(started_node,):
|
||||
started_node.copy_file_to_container(os.path.join(SCRIPT_DIR, "http_server.py"), "/http_server.py")
|
||||
started_node.exec_in_container(["bash", "-c", "python2 /http_server.py"], detach=True, user="root")
|
||||
time.sleep(0.5)
|
||||
started_node.exec_in_container(["bash", "-c", "pkill -11 clickhouse"], user="root")
|
||||
|
||||
result = None
|
||||
for attempt in range(1, 6):
|
||||
time.sleep(0.25 * attempt)
|
||||
result = started_node.exec_in_container(['cat', http_server.RESULT_PATH], user='root')
|
||||
if result == 'OK':
|
||||
break
|
||||
elif result == 'INITIAL_STATE':
|
||||
continue
|
||||
elif result:
|
||||
assert False, 'Unexpected state: ' + result
|
||||
|
||||
assert result == 'OK', 'Crash report not sent'
|
Loading…
Reference in New Issue
Block a user