Skip to content

Commit 83c7750

Browse files
mk-mxphomersimpsons
authored andcommitted
Test timeout issues (exercism#683)
Co-authored-by: homersimpsons <guillaume.alabre@gmail.com>
1 parent 2a8302b commit 83c7750

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

bin/test.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,18 @@ function test {
5858
cp "${exercise_dir}/.meta/${example_file}" "${outdir}/${exercise_file}.${file_ext}"
5959
fi
6060

61-
eval "${PHPUNIT_BIN}" --no-configuration "${outdir}/${test_file}"
61+
# `54s` timeout is an approximation to ensure the tests will not timeont in Exercism Test Runner.
62+
#
63+
# 1. Exercism Test Runner is around 3 times faster than GitHub CI on Ubuntu.
64+
# See: https://forum.exercism.org/t/test-tracks-for-the-20-seconds-limit-on-test-runners/10536/8
65+
# 2. Exercism Test Runner should complete in 20s and involves:
66+
# - Starting Docker container (~1s)
67+
# - Running the test suite
68+
# - Processing the results (~1s)
69+
#
70+
# This gives 18s maximum for the test suite to run in the Exercism Test Runner.
71+
# Hence the test suite should complete in less than 18s x 3 = 54s in GitHub CI on Ubuntu.
72+
timeout 54s "${PHPUNIT_BIN}" --no-configuration "${outdir}/${test_file}"
6273
}
6374

6475
function installed {

exercises/practice/robot-name/RobotNameTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,42 @@ public function testResetName(): void
7373
$this->assertMatchesRegularExpression('/\w{2}\d{3}/', $name2);
7474
}
7575

76+
/**
77+
* PHPUnit ^10.5 has an issue with
78+
* $this->assertArrayNotHasKey($name, $names, sprintf...
79+
* that leads to test timeouts. This is fixed in PHPUnit ^11.
80+
* Revert workaround
81+
* $this->assertFalse(isset($names[$name]), sprintf...
82+
* when upgrading.
83+
*/
7684
public function testNameArentRecycled(): void
7785
{
7886
$names = [];
7987

8088
for ($i = 0; $i < 10000; $i++) {
8189
$name = $this->robot->getName();
82-
$this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after Reset.', $name));
90+
$this->assertFalse(isset($names[$name]), sprintf('Name %s reissued after Reset.', $name));
8391
$names[$name] = true;
8492
$this->robot->reset();
8593
}
8694
}
8795

96+
/**
97+
* PHPUnit ^10.5 has an issue with
98+
* $this->assertArrayNotHasKey($name, $names, sprintf...
99+
* that leads to test timeouts. This is fixed in PHPUnit ^11.
100+
* Revert workaround
101+
* $this->assertFalse(isset($names[$name]), sprintf...
102+
* when upgrading.
103+
*/
88104
// This test is optional.
89105
public function testNameUniquenessManyRobots(): void
90106
{
91107
$names = [];
92108

93109
for ($i = 0; $i < 10000; $i++) {
94110
$name = (new Robot())->getName();
95-
$this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after %d robots', $name, $i));
111+
$this->assertFalse(isset($names[$name]), sprintf('Name %s reissued after %d robots', $name, $i));
96112
$names[$name] = true;
97113
}
98114
}

0 commit comments

Comments
 (0)