| 153 | } |
| 154 | |
| 155 | TVector<NTesting::TPortHolder> GetFreePortsRange(size_t count) const { |
| 156 | Y_ABORT_UNLESS(count > 0); |
| 157 | TVector<NTesting::TPortHolder> ports(Reserve(count)); |
| 158 | for (size_t i = 0; i < Retries; ++i) { |
| 159 | for (auto[left, right] : Ranges_) { |
| 160 | if (right - left < count) { |
| 161 | continue; |
| 162 | } |
| 163 | ui16 start = left + RandomNumber<ui16>((right - left) / 2); |
| 164 | if (right - start < count) { |
| 165 | continue; |
| 166 | } |
| 167 | for (ui16 probe = start; probe < right; ++probe) { |
| 168 | auto port = TryAcquirePort(probe); |
| 169 | if (port) { |
| 170 | ports.emplace_back(std::move(port)); |
| 171 | } else { |
| 172 | ports.clear(); |
| 173 | } |
| 174 | if (ports.size() == count) { |
| 175 | return ports; |
| 176 | } |
| 177 | } |
| 178 | // Can't find required number of ports without gap in the current range |
| 179 | ports.clear(); |
| 180 | } |
| 181 | } |
| 182 | Y_ABORT("Cannot get range of %zu ports!", count); |
| 183 | } |
| 184 | |
| 185 | NTesting::TPortHolder GetPort(ui16 port) const { |
| 186 | if (port && DisableRandomPorts_) { |
no test coverage detected