Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test timeout issues #683

Merged
merged 6 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,23 @@ function test {
cp "${exercise_dir}/.meta/${example_file}" "${outdir}/${exercise_file}.${file_ext}"
fi

eval "${PHPUNIT_BIN}" --no-configuration "${outdir}/${test_file}"
# The time-limit `18` is based on an approximation of the performance.
# Online Test Runner is appr. 3x faster than GitHub CI on Ubuntu.
#
# The total runtime limit of the Online Test Runner is 20 seconds including
# Docker container launch and processing the results. That leaves appr. 18
# seconds for all tests of an exercise. But that's not the `18` here.
#
# The longest running exercise tests in CI are in `alphametics`. It has 3 slow
# test cases (9 letters and 10 letters) that require appr. 15 secs each in CI
# and appr. 5 seconds each in the Online Test Runner.
#
# Putting that together gives a max. of 6 seconds for each of the slow test
# cases in the Online Test Runner before hitting the timeout in production
# -> use 3x 6secs = 18 seconds as a CI limit to ensure tests can actually
# be run in production.
# See: https://forum.exercism.org/t/test-tracks-for-the-20-seconds-limit-on-test-runners/10536/8
mk-mxp marked this conversation as resolved.
Show resolved Hide resolved
eval "${PHPUNIT_BIN}" --default-time-limit 18 --enforce-time-limit --fail-on-risky --no-configuration "${outdir}/${test_file}"
}

function installed {
Expand Down
20 changes: 18 additions & 2 deletions exercises/practice/robot-name/RobotNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,42 @@ public function testResetName(): void
$this->assertMatchesRegularExpression('/\w{2}\d{3}/', $name2);
}

/**
* PHPUnit ^10.5 has an issue with
homersimpsons marked this conversation as resolved.
Show resolved Hide resolved
* $this->assertArrayNotHasKey($name, $names, sprintf...
* that leads to test timeouts. This is fixed in PHPUnit ^11.
* Revert workaround
* $this->assertFalse(isset($names[$name]), sprintf...
* when upgrading.
*/
public function testNameArentRecycled(): void
{
$names = [];

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

/**
* PHPUnit ^10.5 has an issue with
* $this->assertArrayNotHasKey($name, $names, sprintf...
* that leads to test timeouts. This is fixed in PHPUnit ^11.
* Revert workaround
* $this->assertFalse(isset($names[$name]), sprintf...
* when upgrading.
*/
// This test is optional.
public function testNameUniquenessManyRobots(): void
{
$names = [];

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