Skip to content

Commit baf83a6

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. Needed for #TNTP-3709
1 parent dc35274 commit baf83a6

File tree

8 files changed

+137
-30
lines changed

8 files changed

+137
-30
lines changed

.github/workflows/full-ci.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,24 @@ jobs:
4040
with:
4141
tarantool-version: '${{ matrix.tarantool-version }}'
4242

43-
- name: Static code check
44-
uses: ./.github/actions/static-code-check
43+
# - name: Static code check
44+
# uses: ./.github/actions/static-code-check
4545

46-
- name: Unit tests
47-
run: mage unitfull
46+
# - name: Unit tests
47+
# run: mage unitfull
4848

4949
# This server starts and listen on 8084 port that is used for tests.
5050
- name: Stop Mono server
51-
run: sudo systemctl kill mono-xsp4 || true
51+
# netstat is used to help find the cause of TNTP-3709, remove it as soon as it's found.
52+
run: |
53+
sudo systemctl kill mono-xsp4 || echo "failed to kill mono-xsp4 (exit status $?)"
5254
5355
- name: Integration tests
5456
env:
5557
TT_ENABLE_COREDUMP_TESTS: '1'
56-
run: mage integrationfull
58+
# netstat is used to help find the cause of TNTP-3709, remove it as soon as it's found.
59+
run: |
60+
mage integrationfull
5761
5862
full-ci-ce-linux-arm64:
5963
if: false
@@ -132,20 +136,24 @@ jobs:
132136
sdk-version: '${{ matrix.sdk-version }}'
133137
sdk-download-token: '${{ secrets.SDK_DOWNLOAD_TOKEN }}'
134138

135-
- name: Static code check
136-
uses: ./.github/actions/static-code-check
139+
# - name: Static code check
140+
# uses: ./.github/actions/static-code-check
137141

138-
- name: Unit tests
139-
run: mage unitfull
142+
# - name: Unit tests
143+
# run: mage unitfull
140144

141145
# This server starts and listen on 8084 port that is used for tests.
142146
- name: Stop Mono server
143-
run: sudo systemctl kill mono-xsp4 || true
147+
# netstat is used to help find the cause of TNTP-3709, remove it as soon as it's found.
148+
run: |
149+
sudo systemctl kill mono-xsp4 || echo "failed to kill mono-xsp4 (exit status $?)"
144150
145151
- name: Integration tests
146152
env:
147153
TT_ENABLE_COREDUMP_TESTS: '1'
148-
run: mage integrationfull
154+
# netstat is used to help find the cause of TNTP-3709, remove it as soon as it's found.
155+
run: |
156+
mage integrationfull
149157
150158
full-ci-macOS:
151159
if: false

.github/workflows/tests.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,22 @@ jobs:
4848
with:
4949
tarantool-version: '${{ matrix.tarantool-version }}'
5050

51-
- name: Static code check
52-
uses: ./.github/actions/static-code-check
51+
# - name: Static code check
52+
# uses: ./.github/actions/static-code-check
5353

54-
- name: Unit tests
55-
run: mage unit
54+
# - name: Unit tests
55+
# run: mage unit
5656

5757
# This server starts and listen on 8084 port that is used for tests.
5858
- name: Stop Mono server
59-
run: sudo systemctl kill mono-xsp4 || true
59+
# netstat is used to help find the cause of TNTP-3709, remove it as soon as it's found.
60+
run: |
61+
sudo systemctl kill mono-xsp4 || echo "failed to kill mono-xsp4 (exit status $?)"
6062
6163
- name: Integration tests
62-
run: mage integration
64+
# netstat is used to help find the cause of TNTP-3709, remove it as soon as it's found.
65+
run: |
66+
mage integration
6367
6468
tests-ce-linux-arm64:
6569
if: false
@@ -138,18 +142,22 @@ jobs:
138142
sdk-version: '${{ matrix.sdk-version }}'
139143
sdk-download-token: '${{ secrets.SDK_DOWNLOAD_TOKEN }}'
140144

141-
- name: Static code check
142-
uses: ./.github/actions/static-code-check
145+
# - name: Static code check
146+
# uses: ./.github/actions/static-code-check
143147

144-
- name: Unit tests
145-
run: mage unit
148+
# - name: Unit tests
149+
# run: mage unit
146150

147151
# This server starts and listen on 8084 port that is used for tests.
148152
- name: Stop Mono server
149-
run: sudo systemctl kill mono-xsp4 || true
153+
# netstat is used to help find the cause of TNTP-3709, remove it as soon as it's found.
154+
run: |
155+
sudo systemctl kill mono-xsp4 || echo "failed to kill mono-xsp4 (exit status $?)"
150156
151157
- name: Integration tests
152-
run: mage integration
158+
# netstat is used to help find the cause of TNTP-3709, remove it as soon as it's found.
159+
run: |
160+
mage integration
153161
154162
tests-mac-os-ce:
155163
if: false

cli/replicaset/cartridge.go

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,17 @@ func (c *CartridgeApplication) discovery() (Replicasets, error) {
236236
Orchestrator: OrchestratorCartridge,
237237
}
238238

239+
newTopologies := make(map[string]cartridgeTopology, len(c.runningCtx.Instances))
240+
evaledInstances := make([]string, 0, len(c.runningCtx.Instances))
239241
var topology cartridgeTopology
240242
err := EvalForeachAlive(c.runningCtx.Instances, InstanceEvalFunc(
241243
func(inst running.InstanceCtx, evaler connector.Evaler) (bool, error) {
242244
newTopology, err := getCartridgeTopology(evaler)
243245
if err != nil {
244246
return true, err
245247
}
248+
evaledInstances = append(evaledInstances, inst.InstName)
249+
newTopologies[inst.InstName] = newTopology
246250
if topology.IsBootstrapped {
247251
if newTopology.IsBootstrapped {
248252
topology = newTopology
@@ -252,13 +256,38 @@ func (c *CartridgeApplication) discovery() (Replicasets, error) {
252256
}
253257

254258
// Stop if we already found a valid topology.
255-
return topology.IsBootstrapped && !topology.IsCritical, nil
259+
// return topology.IsBootstrapped && !topology.IsCritical, nil
260+
return false, nil
256261
},
257262
))
258263
if err != nil {
259264
return replicasets, fmt.Errorf("failed to get topology: %w", err)
260265
}
261266

267+
for _, instName := range evaledInstances {
268+
newTopology := newTopologies[instName]
269+
if topology.IsBootstrapped {
270+
if newTopology.IsBootstrapped {
271+
topology = newTopology
272+
}
273+
} else {
274+
topology = newTopology
275+
}
276+
}
277+
278+
for _, instName := range evaledInstances {
279+
t := newTopologies[instName]
280+
fmt.Printf("CartridgeApplication.discovery: %s: topology:\n", instName)
281+
fmt.Printf(" IsBootstrapped=%v\n", t.IsBootstrapped)
282+
fmt.Printf(" IsCritical=%v\n", t.IsCritical)
283+
for i, rs := range t.Replicasets {
284+
fmt.Printf(" [%d]: Alias=%s UUID=%s LeaderUUID=%s\n", i, rs.Alias, rs.UUID, rs.LeaderUUID)
285+
for ii, inst := range rs.Instances {
286+
fmt.Printf(" [%d]: Alias=%s UUID=%s URI=%s\n", ii, inst.Alias, inst.UUID, inst.URI)
287+
}
288+
}
289+
}
290+
262291
replicasets = getCartridgeReplicasets(topology)
263292
err = EvalForeachAlive(c.runningCtx.Instances, InstanceEvalFunc(
264293
func(ictx running.InstanceCtx, evaler connector.Evaler) (bool, error) {
@@ -498,6 +527,10 @@ func (c *CartridgeApplication) bootstrapInstance(instanceName, replicasetName st
498527
UUID: &replicasetUUID,
499528
JoinServers: joinOpts,
500529
}}
530+
fmt.Println("bootstrapInstance: opts:")
531+
for i, opt := range opts {
532+
fmt.Printf("[%d]: %+v\n", i, opt)
533+
}
501534
return cartridgeEditReplicasets(evaler, opts, timeout)
502535
}
503536

@@ -608,6 +641,7 @@ func updateCartridgeReplicasets(evaler connector.Evaler, discovered Replicasets,
608641
opts.UUID = &uuid
609642
}
610643
var err error
644+
611645
opts.JoinServers, err = getCartridgeJoinServersOpts(instancesCfg,
612646
rcfg.Instances, instanceUUID)
613647
if err != nil {
@@ -625,7 +659,47 @@ func updateCartridgeReplicasets(evaler connector.Evaler, discovered Replicasets,
625659
editOpts = append(editOpts, opts)
626660
}
627661

628-
return cartridgeEditReplicasets(evaler, editOpts, timeout)
662+
// return cartridgeEditReplicasets(evaler, editOpts, timeout)
663+
err := cartridgeEditReplicasets(evaler, editOpts, timeout)
664+
665+
var dump []string = make([]string, 0, 40)
666+
dump = append(dump, "updateCartridgeReplicasets: replicasetCfg:")
667+
for k, v := range replicasetCfg {
668+
dump = append(dump, fmt.Sprintf(" %s: %+v", k, v))
669+
}
670+
dump = append(dump, "updateCartridgeReplicasets: instancesCfg:")
671+
for k, v := range instancesCfg {
672+
dump = append(dump, fmt.Sprintf(" %s: %+v", k, v))
673+
}
674+
dump = append(dump, "updateCartridgeReplicasets: discovered:")
675+
dump = append(dump, fmt.Sprintf(" State=%s", discovered.State))
676+
dump = append(dump, fmt.Sprintf(" Orchestrator=%s", discovered.Orchestrator))
677+
for i, rs := range discovered.Replicasets {
678+
dump = append(dump, fmt.Sprintf(" [%d]: %+v", i, rs))
679+
}
680+
681+
dump = append(dump, "updateCartridgeReplicasets: setup UUID maps")
682+
for _, replicaset := range discovered.Replicasets {
683+
dump = append(dump, fmt.Sprintf(" %s: %s", replicaset.Alias, replicaset.UUID))
684+
for _, instance := range replicaset.Instances {
685+
dump = append(dump, fmt.Sprintf(" %s: %s", instance.Alias, instance.UUID))
686+
}
687+
}
688+
dump = append(dump, "updateCartridgeReplicasets: replicasetUUID:")
689+
for k, v := range replicasetUUID {
690+
dump = append(dump, fmt.Sprintf(" %s: %s", k, v))
691+
}
692+
dump = append(dump, "updateCartridgeReplicasets: instanceUUID:")
693+
for k, v := range instanceUUID {
694+
dump = append(dump, fmt.Sprintf(" %s: %s", k, v))
695+
}
696+
dump = append(dump, "updateCartridgeReplicasets: editOpts:")
697+
for i, opt := range editOpts {
698+
dump = append(dump, fmt.Sprintf("[%d]: %+v", i, opt))
699+
}
700+
fmt.Println(strings.Join(dump, "\n"))
701+
702+
return err
629703
}
630704

631705
// Expel expels an instance from a Cartridge replicasets.

cli/replicaset/lua/cartridge/edit_replicasets_body.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ local res, err = cartridge.admin_edit_topology({
55
replicasets = replicasets
66
})
77

8-
assert(res, tostring(err))
8+
assert(res, string.format("err:%s replicasets:%s", tostring(err), tostring(replicasets)))

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/cartridge_helper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ def create(self):
175175
# Set replicasets config.
176176
with open(os.path.join(self.workdir, cartridge_name, "replicasets.yml"), "w") as f:
177177
f.write(yaml.dump(self.replicasets_cfg))
178+
with open(os.path.join(self.workdir, cartridge_name, "instances.yml"), "r") as f:
179+
print(f"CartridgeApp.create: instances.yml:\n{f.read()}")
180+
with open(os.path.join(self.workdir, cartridge_name, "replicasets.yml"), "r") as f:
181+
print(f"CartridgeApp.create: replicasets.yml:\n{f.read()}")
178182

179183
def build(self):
180184
cmd = [self.tt_cmd, "build", cartridge_name]
@@ -193,6 +197,7 @@ def start(self, bootstrap_vshard=True):
193197
# Wait for the full start of the cartridge.
194198
for inst in self.instances:
195199
wait_inst_start(self.workdir, inst)
200+
time.sleep(1)
196201

197202
# Bootstrap.
198203
self.bootstrap(bootstrap_vshard=bootstrap_vshard)

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)