Skip to content

Commit

Permalink
Create windows_msvc.yml #130
Browse files Browse the repository at this point in the history
  • Loading branch information
filimonov committed Jan 10, 2022
1 parent 5715d4e commit 5bf3908
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/windows_msvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Windows

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
BUILD_TYPE: Release
# It is impossible to start CH server in docker on Windows due to github actions limitations,
# so limit tests to ones that do no require server interaction.
GTEST_FILTER: --gtest_filter=-"Client/*:*Performance*"

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: ilammy/msvc-dev-cmd@v1

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build/ut
run: Release\clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}"
2 changes: 1 addition & 1 deletion tests/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ADD_EXECUTABLE (simple-test
)

TARGET_LINK_LIBRARIES (simple-test
clickhouse-cpp-lib
clickhouse-cpp-lib-static
)

IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down
2 changes: 1 addition & 1 deletion ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ADD_EXECUTABLE (clickhouse-cpp-ut
)

TARGET_LINK_LIBRARIES (clickhouse-cpp-ut
clickhouse-cpp-lib
clickhouse-cpp-lib-static
gtest-lib
)
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down
32 changes: 27 additions & 5 deletions ut/tcp_server.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#include "tcp_server.h"

#include <iostream>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>

#include <winsock2.h>
/*
#if defined(_win_)
# include <winsock2.h>
#else
# include <netinet/in.h>
# include <sys/socket.h>
# include <unistd.h>
#endif
*/

#include <thread>
#include <unistd.h>

namespace clickhouse {

Expand All @@ -23,7 +32,7 @@ LocalTcpServer::~LocalTcpServer() {
void LocalTcpServer::start() {
//setup a socket
sockaddr_in servAddr;
bzero((char*)&servAddr, sizeof(servAddr));
memset((char*)&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
servAddr.sin_port = htons(port_);
Expand All @@ -33,7 +42,14 @@ void LocalTcpServer::start() {
throw std::runtime_error("Error establishing server socket");
}
int enable = 1;
if (setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {

#if defined(_unix_)
auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
#else
auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, (const char*)&enable, sizeof(enable));
#endif

if (res < 0) {
std::cerr << "setsockopt(SO_REUSEADDR) failed" << std::endl;
}
//bind the socket to its local address
Expand All @@ -47,8 +63,14 @@ void LocalTcpServer::start() {

void LocalTcpServer::stop() {
if(serverSd_ > 0) {

#if defined(_unix_)
shutdown(serverSd_, SHUT_RDWR);
close(serverSd_);
#else
shutdown(serverSd_, SD_BOTH);
closesocket(serverSd_);
#endif
serverSd_ = -1;
}
}
Expand Down
4 changes: 3 additions & 1 deletion ut/tcp_server.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <winsock2.h>

namespace clickhouse {

class LocalTcpServer {
Expand All @@ -15,7 +17,7 @@ class LocalTcpServer {

private:
int port_;
int serverSd_;
SOCKET serverSd_;
};

}
5 changes: 2 additions & 3 deletions ut/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ struct Timer
private:
static auto Now()
{
struct timespec ts;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
return std::chrono::nanoseconds(ts.tv_sec * 1000000000LL + ts.tv_nsec);
std::chrono::nanoseconds ns = std::chrono::high_resolution_clock::now().time_since_epoch();
return ns;
}

private:
Expand Down

0 comments on commit 5bf3908

Please sign in to comment.