Commit aa3bd2a
Fix flaky ClientConfiguratorTest.testFindAvailablePort test (databricks#1058)
## Description
Fixed flaky test `ClientConfiguratorTest.testFindAvailablePort` that was
failing intermittently in CI when sequential ports were unavailable.
The test incorrectly assumed `availablePort + 1` would always be
available, causing it to fail when other processes occupied sequential
ports in busy CI environments (expected port 46512 but received 46513).
**Changes made:**
- Updated test assertions to validate incremental search behavior rather
than expecting specific port values
- Fixed incorrect `setReuseAddress()` usage - was called after binding,
now properly called before binding
- Applied consistent `ServerSocket` creation pattern across all test
cases in the file
This eliminates the race condition that caused intermittent test
failures.
## Testing
- Verified no compilation errors using IDE diagnostics
- Test now validates behavior (incremental port search works) rather
than assuming specific port availability
- Changes follow Java best practices for socket option configuration
## Additional Notes to the Reviewer
The key insight is that the test was testing **implementation details**
(exact port numbers) rather than **behavior** (finds next available
port). The fix makes it robust to different CI/local environments.
Also fixed a subtle bug where `ServerSocket.setReuseAddress(true)` was
being called after the socket was already bound (via the constructor),
making it ineffective. Now properly set before binding.
NO_CHANGELOG=true
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 84a28c9 commit aa3bd2a
File tree
2 files changed
+25
-9
lines changed- src
- main/java/com/databricks/jdbc/dbclient/impl/common
- test/java/com/databricks/jdbc/dbclient/impl/common
2 files changed
+25
-9
lines changedLines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
282 | 283 | | |
283 | 284 | | |
284 | 285 | | |
285 | | - | |
| 286 | + | |
286 | 287 | | |
| 288 | + | |
287 | 289 | | |
288 | 290 | | |
289 | 291 | | |
| |||
Lines changed: 22 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
360 | 361 | | |
361 | 362 | | |
362 | 363 | | |
363 | | - | |
| 364 | + | |
364 | 365 | | |
| 366 | + | |
365 | 367 | | |
366 | 368 | | |
367 | 369 | | |
368 | 370 | | |
369 | 371 | | |
370 | | - | |
371 | | - | |
372 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
373 | 376 | | |
374 | 377 | | |
375 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
376 | 387 | | |
377 | 388 | | |
378 | 389 | | |
| |||
394 | 405 | | |
395 | 406 | | |
396 | 407 | | |
397 | | - | |
398 | | - | |
| 408 | + | |
| 409 | + | |
399 | 410 | | |
| 411 | + | |
400 | 412 | | |
| 413 | + | |
401 | 414 | | |
402 | 415 | | |
403 | 416 | | |
| |||
425 | 438 | | |
426 | 439 | | |
427 | 440 | | |
428 | | - | |
| 441 | + | |
429 | 442 | | |
| 443 | + | |
430 | 444 | | |
431 | 445 | | |
432 | 446 | | |
| |||
0 commit comments