aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/common/network.h
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-03-10 15:37:02 +0300
committeralexv-smirnov <alex@ydb.tech>2023-03-10 15:37:02 +0300
commit394219e982f65dd1ab4e4511051f4c97011c8712 (patch)
treed6a9c3984d7bac6e9564fa451bd28d6edcc063e3 /library/cpp/testing/common/network.h
parent7d576663c816bfaa02dcce5b6dfb8cfc3c7dec67 (diff)
downloadydb-394219e982f65dd1ab4e4511051f4c97011c8712.tar.gz
Add GetPort(port) support to maintain compatibility with unittest TPortManager
Singleton did not allow reinitialisation, so in existing tests this line https://a.yandex-team.ru/arcadia/library/cpp/testing/common/ut/network_ut.cpp?rev=rXXXXXX#L45 did not have any effect. The tests worked just because in both tests the env var PORT_SYNC_PATH was the same and its changes did not affect the tests anyway. As we need to change the env var NO_RANDOM_PORTS to run GetPort( port ) test, I had to make a reinitialisation method, which is now being called from inside the constructor, causing its double invocation during the tests. I could not find a better solution for Singleton(
Diffstat (limited to 'library/cpp/testing/common/network.h')
-rw-r--r--library/cpp/testing/common/network.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/library/cpp/testing/common/network.h b/library/cpp/testing/common/network.h
index eb4d32f3a1..4107145a7c 100644
--- a/library/cpp/testing/common/network.h
+++ b/library/cpp/testing/common/network.h
@@ -33,11 +33,16 @@ namespace NTesting {
[[nodiscard]] TPortHolder GetFreePort();
namespace NLegacy {
- // Do not use this method, it needs only for TPortManager from unittests.
+ // Do not use these methods made for Unittest TPortManager backward compatibility.
// Returns continuous sequence of the specified number of ports.
[[nodiscard]] TVector<TPortHolder> GetFreePortsRange(size_t count);
+ //@brief Returns port from parameter if NO_RANDOM_PORTS env var is set, otherwise first free port
+ [[nodiscard]] TPortHolder GetPort(ui16 port);
}
+ //@brief Reinitialize singleton from environment vars for tests
+ void InitPortManagerFromEnv();
+
//@brief helper class for inheritance
struct TFreePortOwner {
TFreePortOwner() : Port_(GetFreePort()) {}