Skip to content

Commit c4d6023

Browse files
committed
Create windows_msvc.yml #130
1 parent c75b688 commit c4d6023

File tree

6 files changed

+65
-11
lines changed

6 files changed

+65
-11
lines changed

.github/workflows/windows_msvc.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Windows
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
env:
10+
BUILD_TYPE: Release
11+
# It is impossible to start CH server in docker on Windows due to github actions limitations,
12+
# so limit tests to ones that do no require server interaction.
13+
GTEST_FILTER: --gtest_filter=-"Client/*:*Performance*"
14+
15+
jobs:
16+
build:
17+
runs-on: windows-latest
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: ilammy/msvc-dev-cmd@v1
22+
23+
- name: Configure CMake
24+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON
25+
26+
- name: Build
27+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
28+
29+
- name: Test
30+
working-directory: ${{github.workspace}}/build/ut
31+
run: Release\clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}"

tests/simple/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ADD_EXECUTABLE (simple-test
33
)
44

55
TARGET_LINK_LIBRARIES (simple-test
6-
clickhouse-cpp-lib
6+
clickhouse-cpp-lib-static
77
)
88

99
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

ut/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ADD_EXECUTABLE (clickhouse-cpp-ut
2525
)
2626

2727
TARGET_LINK_LIBRARIES (clickhouse-cpp-ut
28-
clickhouse-cpp-lib
28+
clickhouse-cpp-lib-static
2929
gtest-lib
3030
)
3131
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

ut/tcp_server.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#include "tcp_server.h"
22

33
#include <iostream>
4-
#include <netinet/in.h>
54
#include <stdio.h>
65
#include <stdlib.h>
76
#include <string.h>
8-
#include <sys/socket.h>
7+
8+
#include <winsock2.h>
9+
/*
10+
#if defined(_win_)
11+
# include <winsock2.h>
12+
#else
13+
# include <netinet/in.h>
14+
# include <sys/socket.h>
15+
# include <unistd.h>
16+
#endif
17+
*/
18+
919
#include <thread>
10-
#include <unistd.h>
1120

1221
namespace clickhouse {
1322

@@ -23,7 +32,7 @@ LocalTcpServer::~LocalTcpServer() {
2332
void LocalTcpServer::start() {
2433
//setup a socket
2534
sockaddr_in servAddr;
26-
bzero((char*)&servAddr, sizeof(servAddr));
35+
memset((char*)&servAddr, 0, sizeof(servAddr));
2736
servAddr.sin_family = AF_INET;
2837
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
2938
servAddr.sin_port = htons(port_);
@@ -33,7 +42,14 @@ void LocalTcpServer::start() {
3342
throw std::runtime_error("Error establishing server socket");
3443
}
3544
int enable = 1;
36-
if (setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
45+
46+
#if defined(_unix_)
47+
auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
48+
#else
49+
auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, (const char*)&enable, sizeof(enable));
50+
#endif
51+
52+
if (res < 0) {
3753
std::cerr << "setsockopt(SO_REUSEADDR) failed" << std::endl;
3854
}
3955
//bind the socket to its local address
@@ -47,8 +63,14 @@ void LocalTcpServer::start() {
4763

4864
void LocalTcpServer::stop() {
4965
if(serverSd_ > 0) {
66+
67+
#if defined(_unix_)
5068
shutdown(serverSd_, SHUT_RDWR);
5169
close(serverSd_);
70+
#else
71+
shutdown(serverSd_, SD_BOTH);
72+
closesocket(serverSd_);
73+
#endif
5274
serverSd_ = -1;
5375
}
5476
}

ut/tcp_server.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <winsock2.h>
4+
35
namespace clickhouse {
46

57
class LocalTcpServer {
@@ -15,7 +17,7 @@ class LocalTcpServer {
1517

1618
private:
1719
int port_;
18-
int serverSd_;
20+
SOCKET serverSd_;
1921
};
2022

2123
}

ut/utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ struct Timer
3939
private:
4040
static auto Now()
4141
{
42-
struct timespec ts;
43-
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
44-
return std::chrono::nanoseconds(ts.tv_sec * 1000000000LL + ts.tv_nsec);
42+
std::chrono::nanoseconds ns = std::chrono::high_resolution_clock::now().time_since_epoch();
43+
return ns;
4544
}
4645

4746
private:

0 commit comments

Comments
 (0)