ClickHouse/dbms/tests/queries/0_stateless/00463_long_sessions_in_http_interface.sh
proller f6d8436f81 Enable travis (#1772)
* Try travis

* wip

* Try travis

* try

* try

* try

* try

* Revert "try"

This reverts commit 7ecd73c2eb.

* try unbundled

* Try unbundled2

* Try undundled3

* Try unbundled4

* Try5

* try gcc7

* try6

* Try clang

* Try min

* try ccache

* try ccache stats

* no sudo

* try clang

* try ccache

* reset changelog

* Try fix clang

* try limit time

* Faster

* try timeout

* try faster

* Try

* try

* try

* try

* try

* try

* ccache

* Fix

* try test

* try test

* Fix try_listen in some vm's

* fix

* test

* fix

* cache timeout

* packages

* fix

* fix

* fix

* try emb compiler

* Try emb compiler

* Revert "try emb compiler"

This reverts commit 471713cabe.

* try

* Revert "Try emb compiler"

This reverts commit 95e632abf6.

* Skip long

* fix

* fix

* ccache

* fix

* debug

* Fxi test

* test fix

* tes fix

* Fix

* Fix link

* Fix odbc link

* Fxi test

* fix  boost unbundled include

* fix test

* fix test

* test fix

* fix tests

* tests

* Test fail
2018-01-15 21:57:10 +03:00

112 lines
4.3 KiB
Bash
Executable File

#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
request() {
local url="$1"
local select="$2"
${CLICKHOUSE_CURL} --silent $url --data "$select"
}
create_temporary_table() {
local url="$1"
request $url "CREATE TEMPORARY TABLE temp (x String)"
request $url "INSERT INTO temp VALUES ('Hello'), ('World')"
}
check() {
local url="$1"
local select="$2"
local output="$3"
local expected_result="$4"
local message="$5"
result=$(request $url "$select" | grep --count "$output")
if [ $result -ne $expected_result ]; then
echo "FAILED: $message"
exit 1
fi
}
address=${CLICKHOUSE_HOST}
port=${CLICKHOUSE_PORT_HTTP}
url="${CLICKHOUSE_PORT_HTTP_PROTO}://$address:$port/"
session="?session_id=test_$$"
select="SELECT * FROM system.settings WHERE name = 'max_rows_to_read'"
select_from_temporary_table="SELECT * FROM temp ORDER BY x"
select_from_non_existent_table="SELECT * FROM no_such_table ORDER BY x"
check "$url?session_id=no_such_session_$$&session_check=1" "$select" "Exception.*Session not found" 1 "session_check=1 does not work."
check "$url$session&session_check=0" "$select" "Exception" 0 "session_check=0 does not work."
request $url$session "SET max_rows_to_read=7777777"
check "$url$session&session_timeout=string" "$select" "Exception.*Invalid session timeout" 1 "Non-numeric value accepted as a timeout."
check "$url$session&session_timeout=3601" "$select" "Exception.*Maximum session timeout*" 1 "More then 3600 seconds accepted as a timeout."
check "$url$session&session_timeout=-1" "$select" "Exception.*Invalid session timeout" 1 "Negative timeout accepted."
check "$url$session&session_timeout=0" "$select" "Exception" 0 "Zero timeout not accepted."
check "$url$session&session_timeout=3600" "$select" "Exception" 0 "3600 second timeout not accepted."
check "$url$session&session_timeout=60" "$select" "Exception" 0 "60 second timeout not accepted."
check $url$session "$select" "7777777" 1 "Failed to reuse session."
# Workaround here
# TODO: move the test to integration test or add readonly user to test environment
if [[ -z `request "$url?user=readonly" "SELECT ''"` ]]; then
# We have readonly user
check "$url$session&user=readonly&session_check=1" "$select" "Exception.*Session not found" 1 "Session is accessable for another user."
else
check "$url$session&user=readonly&session_check=1" "$select" "Exception.*Unknown user*" 1 "Session is accessable for unknown user."
fi
create_temporary_table $url$session
check $url$session "$select_from_temporary_table" "Hello" 1 "Failed to reuse a temporary table for session."
check "$url?session_id=another_session_$$" "$select_from_temporary_table" "Exception.*Table .* doesn't exist." 1 "Temporary table is visible for another table."
( (
cat <<EOF
POST /$session HTTP/1.1
Host: $address:$port
Accept: */*
Content-Length: 62
Content-Type: application/x-www-form-urlencoded
EOF
sleep 4
) | telnet $address $port >/dev/null 2>/dev/null) &
sleep 1
check $url$session "$select" "Exception.*Session is locked" 1 "Double access to the same session."
session="?session_id=test_timeout_$$"
create_temporary_table "$url$session&session_timeout=1"
check "$url$session&session_timeout=1" "$select_from_temporary_table" "Hello" 1 "Failed to reuse a temporary table for session."
sleep 3
check "$url$session&session_check=1" "$select" "Exception.*Session not found" 1 "Session did not expire on time."
create_temporary_table "$url$session&session_timeout=2"
for i in $(seq 1 3); do
check "$url$session&session_timeout=2" "$select_from_temporary_table" "Hello" 1 "Session expired too early."
sleep 1
done
sleep 3
check "$url$session&session_check=1" "$select" "Exception.*Session not found" 1 "Session did not expire on time."
create_temporary_table "$url$session&session_timeout=2"
for i in $(seq 1 5); do
check "$url$session&session_timeout=2" "$select_from_non_existent_table" "Exception.*Table .* doesn't exist." 1 "Session expired too early."
sleep 1
done
check "$url$session&session_timeout=2" "$select_from_temporary_table" "Hello" 1 "Session expired too early. Failed to update timeout in case of exceptions."
sleep 4
check "$url$session&session_check=1" "$select" "Exception.*Session not found" 1 "Session did not expire on time."
echo "PASSED"