Caffe2 - C++ API
A deep learning, cross platform ML framework
data_channel_tcp_accept_timeout.cpp
1 #include <THD/base/data_channels/DataChannelTCP.hpp>
2 #include <THD/test/TestUtils.hpp>
3 
4 #include <cassert>
5 #include <iostream>
6 #include <memory>
7 #include <thread>
8 
9 constexpr int WORKERS_NUM = 2;
10 constexpr int MASTER_PORT = 45680;
11 
12 void master() {
13  setenv(WORLD_SIZE_ENV, std::to_string((WORKERS_NUM + 1)).data(), 1);
14  setenv(RANK_ENV, "0", 1);
15  setenv(MASTER_PORT_ENV, std::to_string(MASTER_PORT).data(), 1);
16  auto masterChannel = std::make_shared<thd::DataChannelTCP>(
17  thd::getInitConfig("env://"), 2000); // timeout after 2s
18 
19  ASSERT_THROWS(std::exception, masterChannel->init())
20 }
21 
22 int main() {
23  std::thread master_thread(master);
24  master_thread.join();
25  std::cout << "OK" << std::endl;
26  return 0;
27 }