Skip to content

Commit 679f033

Browse files
karenc-bqyanw-bq
authored andcommitted
Dockerize test containers (#52)
- Set up test framework for running tests in isolated dockerized containers
1 parent 5225055 commit 679f033

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3567
-12
lines changed

Diff for: .github/workflows/dockerized.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Build and Run Dockerized Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
paths-ignore:
8+
- '**/*.md'
9+
10+
env:
11+
BUILD_TYPE: Release
12+
13+
jobs:
14+
build-dockerized-tests:
15+
name: Build and Run Tests in Docker
16+
runs-on: ubuntu-latest
17+
env:
18+
CMAKE_GENERATOR: Unix Makefiles
19+
20+
steps:
21+
- name: Checkout source code
22+
uses: actions/checkout@v2
23+
24+
# Configure build environment/dependencies
25+
- name: Install MySQL client libs & other dependencies
26+
run: sudo apt-get update && sudo apt-get install
27+
build-essential
28+
libgtk-3-dev
29+
libmysqlclient-dev
30+
unixodbc
31+
unixodbc-dev
32+
33+
- name: Create build environment
34+
shell: bash
35+
run: cmake -E make_directory ${{ github.workspace }}/build
36+
37+
- name: Configure CMake
38+
shell: bash
39+
run: cmake -S . -B build
40+
-G "$CMAKE_GENERATOR"
41+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
42+
-DMYSQLCLIENT_STATIC_LINKING=true
43+
-DWITH_UNIXODBC=1
44+
45+
# Build driver
46+
- name: Build driver
47+
working-directory: ${{ github.workspace }}/build
48+
shell: bash
49+
run: cmake --build . --config $BUILD_TYPE
50+
51+
- name: 'Set up JDK 8'
52+
uses: actions/setup-java@v1
53+
with:
54+
java-version: 8
55+
56+
- name: 'Run Integration Tests'
57+
working-directory: ${{ github.workspace }}/testframework
58+
run: |
59+
./gradlew --no-parallel --no-daemon test-docker --info
60+
env:
61+
TEST_USERNAME: ${{ secrets.TEST_USERNAME }}
62+
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
63+
TEST_DB_CLUSTER_IDENTIFIER: ${{ secrets.TEST_DB_CLUSTER_IDENTIFIER }}-${{ github.run_id }}
64+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
65+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
66+
DRIVER_PATH: ${{ github.workspace }}/build
67+
68+
- name: 'Archive junit results'
69+
if: always()
70+
uses: actions/upload-artifact@v2
71+
with:
72+
name: 'junit-report'
73+
path: build/reports/tests/
74+
retention-days: 5

Diff for: .gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,26 @@ Uninstall.bat
5454
*.sln
5555
**/*.aps
5656

57+
# Java build files
58+
testframework/bin/
59+
testframework/build/
60+
testframework/buildtest/
61+
testframework/dist/
62+
testframework/nbproject/
63+
testframework/patches/
64+
*~
65+
*.lock
66+
*.swp
67+
*.DS_Store
68+
*.diff
69+
*.dot
70+
*.dot.png
71+
*.class
72+
*.iml
73+
*.project.elrade
74+
*.attach_pid*
75+
*.gradle
76+
*.idea
77+
testframework/hs_err_pid*.log
78+
*.sh
79+

Diff for: CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ ENDIF(NOT DISABLE_GUI)
518518
ADD_SUBDIRECTORY(dltest)
519519
ADD_SUBDIRECTORY(installer)
520520
ADD_SUBDIRECTORY(test)
521+
ADD_SUBDIRECTORY(integration)
521522

522523
IF(ENABLE_GTESTS)
523524
ADD_SUBDIRECTORY(testing)
File renamed without changes.

Diff for: driver/topology_service.cc

+1-5
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ std::shared_ptr<CLUSTER_TOPOLOGY_INFO> TOPOLOGY_SERVICE::query_for_topology(CONN
247247
if (connection->try_execute_query(RETRIEVE_TOPOLOGY_SQL)) {
248248
topology_info = std::make_shared<CLUSTER_TOPOLOGY_INFO>();
249249
MYSQL_ROW row;
250-
while (row = connection->fetch_next_row()) {
250+
while ((row = connection->fetch_next_row())) {
251251
std::shared_ptr<HOST_INFO> host_info = create_host(row);
252252
if (host_info) {
253253
topology_info->add_host(host_info);
@@ -268,9 +268,5 @@ std::string TOPOLOGY_SERVICE::get_host_endpoint(const char* node_name) {
268268
if (position != std::string::npos) {
269269
host.replace(position, 1, node_name);
270270
}
271-
else {
272-
throw "Invalid host template for TOPOLOGY_SERVICE";
273-
}
274-
275271
return host;
276272
}

Diff for: installer/myodbc-installer.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,12 @@ int list_datasource_details(DataSource *ds)
574574
if (ds->allow_reader_connections) printf("\tALLOW_READER_CONNECTIONS\n");
575575
if (ds->gather_perf_metrics) printf("\tGATHER_PERF_METRICS\n");
576576
if (ds->topology_refresh_rate) printf("\tTOPOLOGY_REFRESH_RATE=%d\n", ds->topology_refresh_rate);
577-
if (ds->failover_timeout) printf("\FAILOVER_TIMEOUT=%d\n", ds->failover_timeout);
578-
if (ds->failover_topology_refresh_rate) printf("\FAILOVER_TOPOLOGY_REFRESH_RATE=%d\n", ds->failover_topology_refresh_rate);
579-
if (ds->failover_writer_reconnect_interval) printf("\FAILOVER_WRITER_RECONNECT_INTERVAL=%d\n", ds->failover_writer_reconnect_interval);
580-
if (ds->failover_reader_connect_timeout) printf("\FAILOVER_READER_CONNECT_TIMEOUT=%d\n", ds->failover_reader_connect_timeout);
581-
if (ds->connect_timeout) printf("\CONNECT_TIMEOUT=%d\n", ds->connect_timeout);
582-
if (ds->network_timeout) printf("\NETWORK_TIMEOUT=%d\n", ds->network_timeout);
577+
if (ds->failover_timeout) printf("\tFAILOVER_TIMEOUT=%d\n", ds->failover_timeout);
578+
if (ds->failover_topology_refresh_rate) printf("\tFAILOVER_TOPOLOGY_REFRESH_RATE=%d\n", ds->failover_topology_refresh_rate);
579+
if (ds->failover_writer_reconnect_interval) printf("\tFAILOVER_WRITER_RECONNECT_INTERVAL=%d\n", ds->failover_writer_reconnect_interval);
580+
if (ds->failover_reader_connect_timeout) printf("\tFAILOVER_READER_CONNECT_TIMEOUT=%d\n", ds->failover_reader_connect_timeout);
581+
if (ds->connect_timeout) printf("\tCONNECT_TIMEOUT=%d\n", ds->connect_timeout);
582+
if (ds->network_timeout) printf("\tNETWORK_TIMEOUT=%d\n", ds->network_timeout);
583583

584584
return 0;
585585
}

Diff for: integration/CMakeLists.txt

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#
2+
# AWS ODBC Driver for MySQL
3+
# Copyright Amazon.com Inc. or affiliates.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# 1. Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions and the following disclaimer.
10+
#
11+
# 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25+
# POSSIBILITY OF SUCH DAMAGE.
26+
#
27+
28+
cmake_minimum_required(VERSION 3.14)
29+
30+
project(integration)
31+
32+
# GoogleTest requires at least C++11
33+
set(CMAKE_CXX_STANDARD 11)
34+
35+
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/toxiproxy")
36+
37+
#-------------- unixodbc/iodbc/win -------------------
38+
if(WIN32)
39+
set(ODBCLIB odbc32)
40+
else(WIN32)
41+
if(WITH_UNIXODBC)
42+
set(ODBCLIB odbc)
43+
else(WITH_UNIXODBC)
44+
set(ODBCLIB iodbc)
45+
endif(WITH_UNIXODBC)
46+
endif(WIN32)
47+
48+
include(FetchContent)
49+
FetchContent_Declare(
50+
googletest
51+
URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip
52+
)
53+
54+
# For Windows: Prevent overriding the parent project's compiler/linker settings
55+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
56+
57+
FetchContent_MakeAvailable(googletest)
58+
59+
enable_testing()
60+
61+
add_executable(
62+
integration
63+
simple_connect_test.cc
64+
simple_toxiproxy_test.cc
65+
)
66+
67+
include(GoogleTest)
68+
69+
gtest_discover_tests(integration)
70+
71+
target_include_directories(integration PUBLIC "${httplib_SOURCE_DIR}")
72+
73+
target_link_libraries(
74+
integration
75+
nlohmann_json::nlohmann_json
76+
${ODBCLIB}
77+
gtest_main
78+
toxiproxy
79+
)
80+
81+
set_target_properties(integration PROPERTIES
82+
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

Diff for: integration/simple_connect_test.cc

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* AWS ODBC Driver for MySQL
3+
* Copyright Amazon.com Inc. or affiliates.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
16+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18+
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*
25+
*/
26+
27+
#ifdef _WIN32
28+
#include <windows.h>
29+
#else
30+
#include <stdio.h>
31+
#endif
32+
33+
#include <cstdlib>
34+
#include <sql.h>
35+
#include <sqlext.h>
36+
#include <gtest/gtest.h>
37+
38+
#define MAX_NAME_LEN 255
39+
#define SQL_MAX_MESSAGE_LENGTH 512
40+
41+
static SQLHENV env;
42+
static SQLHDBC dbc;
43+
44+
class FailoverIntegrationTest : public testing::Test
45+
{
46+
protected:
47+
char* dsn = std::getenv("TEST_DSN");
48+
char* db = std::getenv("TEST_DATABASE");
49+
char* user = std::getenv("TEST_UID");
50+
char* pwd = std::getenv("TEST_PASSWORD");
51+
char* server = std::getenv("TEST_SERVER");
52+
53+
SQLCHAR connIn[4096] = {}, connOut[4096] = {}, sqlstate[6] = {}, message[SQL_MAX_MESSAGE_LENGTH] = {};
54+
SQLSMALLINT len = 0, length = 0;
55+
SQLINTEGER native_error = 0;
56+
57+
static void SetUpTestSuite()
58+
{
59+
SQLAllocHandle(SQL_HANDLE_ENV, nullptr, &env);
60+
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<SQLPOINTER>(SQL_OV_ODBC3), 0);
61+
SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
62+
}
63+
64+
static void TearDownTestSuite()
65+
{
66+
if (nullptr != dbc)
67+
SQLFreeHandle(SQL_HANDLE_DBC, dbc);
68+
if (nullptr != env)
69+
SQLFreeHandle(SQL_HANDLE_ENV, env);
70+
}
71+
};
72+
73+
TEST_F(FailoverIntegrationTest, SimpleTest)
74+
{
75+
sprintf(reinterpret_cast<char*>(connIn), "DSN=%s;UID=%s;PWD=%s;SERVER=%s;", dsn, user, pwd, server);
76+
77+
const SQLRETURN rc = SQLDriverConnect(dbc, nullptr, connIn, SQL_NTS, connOut, MAX_NAME_LEN, &len, SQL_DRIVER_NOPROMPT);
78+
SQLRETURN drc = SQLGetDiagRec(SQL_HANDLE_DBC, dbc, 1, sqlstate, &native_error, message, SQL_MAX_MESSAGE_LENGTH - 1, &length);
79+
80+
if (SQL_SUCCEEDED(drc))
81+
printf("# [%6s] %*sd\n", sqlstate, length, message);
82+
83+
EXPECT_EQ(SQL_SUCCESS, rc);
84+
85+
EXPECT_EQ(SQL_SUCCESS, SQLDisconnect(dbc));
86+
}

0 commit comments

Comments
 (0)