Skip to content

Commit 9c3b3c8

Browse files
committed
ci: display port usage information
It might help to identify the reason of flaky test `test_replicaset_bootstrap_cartridge_app_second_bootstrap` when/if it fails next time. Closes #TNTP-3709
1 parent dc35274 commit 9c3b3c8

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

cli/replicaset/cartridge.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,16 @@ func (c *CartridgeApplication) discovery() (Replicasets, error) {
245245
}
246246
if topology.IsBootstrapped {
247247
if newTopology.IsBootstrapped {
248+
updateInstancesAliases(newTopology.Replicasets, topology.Replicasets)
248249
topology = newTopology
249250
}
250251
} else {
251252
topology = newTopology
252253
}
253254

254255
// Stop if we already found a valid topology.
255-
return topology.IsBootstrapped && !topology.IsCritical, nil
256+
return topology.IsBootstrapped && !topology.IsCritical &&
257+
!hasMissingInstancesAliases(topology.Replicasets), nil
256258
},
257259
))
258260
if err != nil {
@@ -271,6 +273,37 @@ func (c *CartridgeApplication) discovery() (Replicasets, error) {
271273
return recalculateMasters(replicasets), err
272274
}
273275

276+
// hasMissingInstancesAliases checks if any instance has empty alias.
277+
func hasMissingInstancesAliases(replicasets []Replicaset) bool {
278+
for _, rs := range replicasets {
279+
for _, inst := range rs.Instances {
280+
if len(inst.Alias) == 0 {
281+
return true
282+
}
283+
}
284+
}
285+
return false
286+
}
287+
288+
// updateInstancesAliases tries to update missing instances aliases with another instances data.
289+
func updateInstancesAliases(replicasets []Replicaset, other []Replicaset) {
290+
instAliases := make(map[string]string, 0)
291+
for _, rs := range other {
292+
for _, inst := range rs.Instances {
293+
instAliases[inst.UUID] = inst.Alias
294+
}
295+
}
296+
for i, rs := range replicasets {
297+
for ii, inst := range rs.Instances {
298+
if len(inst.Alias) == 0 {
299+
if alias, ok := instAliases[inst.UUID]; ok && len(alias) > 0 {
300+
replicasets[i].Instances[ii].Alias = alias
301+
}
302+
}
303+
}
304+
}
305+
}
306+
274307
// Promote promotes an instance in the cartridge application.
275308
func (c *CartridgeApplication) Promote(ctx PromoteCtx) error {
276309
replicasets, err := c.Discovery(UseCache)

magefile.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,16 +420,18 @@ func (Unit) Coverage() error {
420420
func Integration() error {
421421
fmt.Println("Running integration tests...")
422422

423+
test_name := "test_replicaset_bootstrap_cartridge_app_second_bootstrap"
423424
return sh.RunV(pythonExecutableName, "-m", "pytest", "-m", "not slow and not slow_ee "+
424-
"and not notarantool", "test/integration")
425+
"and not notarantool", "-k", test_name, "--maxfail=1", "test/integration")
425426
}
426427

427428
// Run full set of integration tests.
428429
func IntegrationFull() error {
429430
fmt.Println("Running all integration tests...")
430431

432+
test_name := "test_replicaset_bootstrap_cartridge_app_second_bootstrap"
431433
return sh.RunV(pythonExecutableName, "-m", "pytest", "-m", "not slow_ee and not notarantool",
432-
"test/integration")
434+
"-k", test_name, "--maxfail=1", "test/integration")
433435
}
434436

435437
// Run full set of integration tests, excluding docker tests.

test/integration/replicaset/test_replicaset_bootstrap.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ def test_bootstrap_app_replicaset_specified(tt_cmd, tmpdir_with_cfg):
128128

129129

130130
@pytest.mark.skipif(tarantool_major_version > 2, reason="skip cartridge test for Tarantool > 2")
131+
@pytest.mark.parametrize("attempt", range(100))
131132
@pytest.mark.parametrize("flag", [None, "--cartridge"])
132-
def test_replicaset_bootstrap_cartridge_app_second_bootstrap(tt_cmd, cartridge_app, flag):
133+
def test_replicaset_bootstrap_cartridge_app_second_bootstrap(tt_cmd, cartridge_app, flag, attempt):
134+
print(f"Attempt #{attempt}")
133135
# Change the config.
134136
replicasets_cfg = {
135137
"router": {
@@ -159,8 +161,14 @@ def test_replicaset_bootstrap_cartridge_app_second_bootstrap(tt_cmd, cartridge_a
159161
"vshard_group": "default",
160162
},
161163
}
164+
with open(os.path.join(cartridge_app.workdir, cartridge_name, "instances.yml"), "r") as f:
165+
print(f"test: instances.yml:\n{f.read()}")
166+
with open(os.path.join(cartridge_app.workdir, cartridge_name, "replicasets.yml"), "r") as f:
167+
print(f"test: replicasets.yml #1:\n{f.read()}")
162168
with open(os.path.join(cartridge_app.workdir, cartridge_name, "replicasets.yml"), "w") as f:
163169
f.write(yaml.dump(replicasets_cfg))
170+
with open(os.path.join(cartridge_app.workdir, cartridge_name, "replicasets.yml"), "r") as f:
171+
print(f"test: replicasets.yml #2:\n{f.read()}")
164172

165173
# Run bootstrap after initial bootstrap again.
166174
cmd = [tt_cmd, "rs", "bootstrap"]

test/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,11 @@ def find_ports(n=1, port=8000):
446446
if s.connect_ex(("localhost", port)) == 0:
447447
busy = True
448448
break
449+
print(f"find_ports({n}): is port {port} busy... {busy}")
449450
if not busy:
450451
ports.append(port)
451452
port += 1
453+
print(f"find_ports({n}): {ports}")
452454
return ports
453455

454456

0 commit comments

Comments
 (0)