Skip to content

Commit abe48ee

Browse files
committed
Better tests & GH actions
1 parent f0c2870 commit abe48ee

File tree

14 files changed

+153
-92
lines changed

14 files changed

+153
-92
lines changed

.github/workflows/linux.yml

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8-
workflow_call:
9-
inputs:
10-
extra_cmake_flags:
11-
required: false
12-
type: string
13-
extra_install:
14-
required: false
15-
type: string
16-
gtest_filter:
17-
required: false
18-
type: string
19-
default: "*"
208

219
env:
2210
BUILD_TYPE: Release
@@ -26,37 +14,44 @@ jobs:
2614
runs-on: ubuntu-latest
2715
strategy:
2816
matrix:
29-
build: [clang-6, gcc-7, gcc-8, gcc-9]
17+
build: [clang-6-ssl, gcc-7-ssl, gcc-8-ssl, gcc-9-ssl, gcc-9]
18+
3019
include:
31-
- build: clang-6
32-
os: ubuntu-latest
20+
- build: clang-6-ssl
3321
INSTALL: clang-6.0
3422
C_COMPILER: clang-6.0
3523
CXX_COMPILER: clang++-6.0
24+
extra_cmake_flags: -DWITH_OPENSSL=ON
3625

37-
- build: gcc-7
38-
os: ubuntu-latest
39-
INSTALL: gcc-7 g++-7
26+
- build: gcc-7-ssl
27+
INSTALL: gcc-7 g++-7 libssl-dev
4028
C_COMPILER: gcc-7
4129
CXX_COMPILER: g++-7
30+
extra_cmake_flags: -DWITH_OPENSSL=ON
4231

43-
- build: gcc-8
44-
os: ubuntu-latest
32+
- build: gcc-8-ssl
4533
INSTALL: gcc-8 g++-8
4634
C_COMPILER: gcc-8
4735
CXX_COMPILER: g++-8
36+
extra_cmake_flags: -DWITH_OPENSSL=ON
37+
38+
- build: gcc-9-ssl
39+
INSTALL: gcc-9 g++-9
40+
C_COMPILER: gcc-9
41+
CXX_COMPILER: g++-9
42+
extra_cmake_flags: -DWITH_OPENSSL=ON
4843

4944
- build: gcc-9
50-
os: ubuntu-latest
5145
INSTALL: gcc-9 g++-9
5246
C_COMPILER: gcc-9
5347
CXX_COMPILER: g++-9
48+
extra_cmake_flags: -DWITH_OPENSSL=OFF
5449

5550
steps:
5651
- uses: actions/checkout@v2
5752

5853
- name: Install dependencies
59-
run: sudo apt-get install -y cmake ${{ matrix.INSTALL }} ${{ inputs.extra_install }}
54+
run: sudo apt-get install -y cmake ${{ matrix.INSTALL }}
6055

6156
- name: Configure CMake
6257
run: |
@@ -65,7 +60,7 @@ jobs:
6560
-DCMAKE_CXX_COMPILER=${{ matrix.CXX_COMPILER}} \
6661
-B ${{github.workspace}}/build \
6762
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON \
68-
${{ inputs.extra_cmake_flags }}
63+
${{ matrix.extra_cmake_flags }}
6964
7065
- name: Build
7166
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target all
@@ -84,4 +79,4 @@ jobs:
8479
8580
- name: Test
8681
working-directory: ${{github.workspace}}/build/ut
87-
run: ./clickhouse-cpp-ut --gtest_filter="${{inputs.gtest_filter}}"
82+
run: ./clickhouse-cpp-ut

.github/workflows/linux_ssl.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/macos.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,54 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8-
workflow_call:
9-
inputs:
10-
extra_cmake_flags:
11-
required: false
12-
type: string
13-
extra_install:
14-
required: false
15-
type: string
16-
gtest_filter:
17-
required: false
18-
type: string
19-
default: "*"
208

219
env:
2210
BUILD_TYPE: Release
11+
CLICKHOUSE_USER: clickhouse_cpp_cicd
12+
CLICKHOUSE_PASSWORD: clickhouse_cpp_cicd
2313

2414
jobs:
2515
build:
2616
runs-on: macos-latest
2717

18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
build: [nossl, ssl]
22+
include:
23+
- build: nossl
24+
extra_cmake_flags: -DWITH_OPENSSL=OFF
25+
extra_install:
26+
27+
- build: ssl
28+
extra_cmake_flags: -DWITH_OPENSSL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/
29+
extra_install: openssl
30+
2831
steps:
2932
- uses: actions/checkout@v2
3033

3134
- name: Install dependencies
32-
run: brew install cmake ${{inputs.extra_install}}
35+
run: brew install cmake ${{matrix.extra_install}}
3336

3437
- name: Configure CMake
35-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON ${{inputs.extra_cmake_flags}}
38+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON ${{matrix.extra_cmake_flags}}
3639

3740
- name: Build
3841
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target all
3942

43+
- name: Start tls offoader proxy
44+
# that mimics non-secure clickhouse running on localhost
45+
# by tunneling queries to remote tls server
46+
# (needed because we can't start real clickhouse instance on windows)
47+
run: |
48+
wget https://github.com/filimonov/go-tlsoffloader/releases/download/v0.1.2/go-tlsoffloader_0.1.2_Darwin_x86_64.tar.gz
49+
tar -xvzf go-tlsoffloader_0.1.2_Darwin_x86_64.tar.gz
50+
./go-tlsoffloader -l localhost:9000 -b github.demo.trial.altinity.cloud:9440 &
51+
4052
- name: Test
4153
working-directory: ${{github.workspace}}/build/ut
4254
env:
4355
# It is impossible to start CH server in docker on macOS due to github actions limitations,
4456
# so limit tests to ones that do no require server interaction.
4557
GTEST_FILTER_ONLY_LOCAL: "-Client/*"
46-
run: ./clickhouse-cpp-ut --gtest_filter="${{inputs.gtest_filter}}:${{env.GTEST_FILTER_ONLY_LOCAL}}"
58+
run: ./clickhouse-cpp-ut

.github/workflows/macos_ssl.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

bench/bench.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
namespace clickhouse {
66

77
Client g_client(ClientOptions()
8-
.SetHost("localhost")
8+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
9+
.SetPort( std::stoi(getEnvOrDefault("CLICKHOUSE_PORT", "9000")))
10+
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
11+
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
12+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
913
.SetPingBeforeQuery(false));
1014

1115
static void SelectNumber(benchmark::State& state) {

clickhouse/base/socket.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#endif
1919

2020
namespace clickhouse {
21+
2122
namespace {
2223

2324
class LocalNames : public std::unordered_set<std::string> {

tests/simple/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ TARGET_LINK_LIBRARIES (simple-test
66
clickhouse-cpp-lib
77
)
88

9+
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
10+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --rtlib=compiler-rt")
11+
ENDIF ()

tests/simple/main.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
using namespace clickhouse;
1414
using namespace std;
1515

16+
std::string getEnvOrDefault(const std::string& env, const std::string& default_val)
17+
{
18+
const char* v = std::getenv(env.c_str());
19+
return v ? v : default_val;
20+
}
21+
1622
inline void PrintBlock(const Block& block) {
1723
for (Block::Iterator bi(block); bi.IsValid(); bi.Next()) {
1824
std::cout << bi.Name() << " ";
@@ -498,14 +504,22 @@ int main() {
498504
try {
499505
{
500506
Client client(ClientOptions()
501-
.SetHost("localhost")
507+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
508+
.SetPort( std::stoi(getEnvOrDefault("CLICKHOUSE_PORT", "9000")))
509+
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
510+
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
511+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
502512
.SetPingBeforeQuery(true));
503513
RunTests(client);
504514
}
505515

506516
{
507517
Client client(ClientOptions()
508-
.SetHost("localhost")
518+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
519+
.SetPort( std::stoi(getEnvOrDefault("CLICKHOUSE_PORT", "9000")))
520+
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
521+
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
522+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
509523
.SetPingBeforeQuery(true)
510524
.SetCompressionMethod(CompressionMethod::LZ4));
511525
RunTests(client);

ut/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ TARGET_LINK_LIBRARIES (clickhouse-cpp-ut
2828
clickhouse-cpp-lib
2929
gtest-lib
3030
)
31+
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
32+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --rtlib=compiler-rt")
33+
ENDIF ()

ut/client_ut.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <clickhouse/client.h>
22
#include "readonly_client_test.h"
33
#include "connection_failed_client_test.h"
4+
#include "utils.h"
45
#include <gtest/gtest.h>
56

67
#include <cmath>
@@ -883,10 +884,51 @@ INSTANTIATE_TEST_SUITE_P(
883884
Client, ClientCase,
884885
::testing::Values(
885886
ClientOptions()
886-
.SetHost("localhost")
887+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
888+
.SetPort( std::stoi(getEnvOrDefault("CLICKHOUSE_PORT", "9000")))
889+
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
890+
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
891+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
887892
.SetPingBeforeQuery(true),
888893
ClientOptions()
889-
.SetHost("localhost")
894+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
895+
.SetPort( std::stoi(getEnvOrDefault("CLICKHOUSE_PORT", "9000")))
896+
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
897+
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
898+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
890899
.SetPingBeforeQuery(false)
891900
.SetCompressionMethod(CompressionMethod::LZ4)
892901
));
902+
903+
namespace {
904+
using namespace clickhouse;
905+
906+
const auto QUERIES = std::vector<std::string>{"SELECT version()", "SELECT fqdn()", "SELECT buildId()",
907+
"SELECT uptime()", "SELECT filesystemFree()", "SELECT now()"};
908+
}
909+
910+
INSTANTIATE_TEST_SUITE_P(ClientLocalReadonly, ReadonlyClientTest,
911+
::testing::Values(ReadonlyClientTest::ParamType{
912+
ClientOptions()
913+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
914+
.SetPort( std::stoi(getEnvOrDefault("CLICKHOUSE_PORT", "9000")))
915+
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
916+
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
917+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
918+
.SetSendRetries(1)
919+
.SetPingBeforeQuery(true)
920+
.SetCompressionMethod(CompressionMethod::None),
921+
QUERIES}));
922+
923+
INSTANTIATE_TEST_SUITE_P(ClientLocalFailed, ConnectionFailedClientTest,
924+
::testing::Values(ConnectionFailedClientTest::ParamType{
925+
ClientOptions()
926+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
927+
.SetPort( std::stoi(getEnvOrDefault("CLICKHOUSE_PORT", "9000")))
928+
.SetUser("non_existing_user_clickhouse_cpp_test")
929+
.SetPassword("wrongpwd")
930+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
931+
.SetSendRetries(1)
932+
.SetPingBeforeQuery(true)
933+
.SetCompressionMethod(CompressionMethod::None),
934+
"Authentication failed: password is incorrect"}));

ut/performance_tests.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ TYPED_TEST_P(ColumnPerformanceTest, InsertAndSelect) {
171171
const std::string column_name = "column";
172172

173173
auto column = InstantiateColumn<ColumnType>();
174-
Client client(ClientOptions().SetHost("localhost"));
174+
Client client(ClientOptions()
175+
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
176+
.SetPort( std::stoi(getEnvOrDefault("CLICKHOUSE_PORT", "9000")))
177+
.SetUser( getEnvOrDefault("CLICKHOUSE_USER", "default"))
178+
.SetPassword( getEnvOrDefault("CLICKHOUSE_PASSWORD", ""))
179+
.SetDefaultDatabase(getEnvOrDefault("CLICKHOUSE_DB", "default"))
180+
);
175181
client.Execute("CREATE DATABASE IF NOT EXISTS PerformanceTests");
176182
client.Execute("DROP TABLE IF EXISTS PerformanceTests.ColumnTest");
177183
client.Execute("CREATE TABLE PerformanceTests.ColumnTest (" + column_name + " " + column.Type()->GetName() + ") ENGINE = Memory");

0 commit comments

Comments
 (0)