Skip to content

Commit

Permalink
[api/tests] Run API tests in separate job (#8802)
Browse files Browse the repository at this point in the history
This removes the API tests from the integrationtests target and moves them into a separate job in GitHub Actions. The result is that we can see the status of tests against different API versions without trying to debug the dockerized integration tests.

Since the API tests do not depend on Selenium, these tests are run directly on the Github Actions image and bypass docker compose. A step is added at the end to print the error log, so that it's easier to see what went wrong.

Theoretically, this should also make the integration tests finish faster since they no longer run the API tests. (In practice, this is going to depend on the number of jobs GitHub runs in parallel.)
  • Loading branch information
driusan authored Jun 20, 2023
1 parent c164986 commit 1cd5f07
Show file tree
Hide file tree
Showing 25 changed files with 156 additions and 13 deletions.
109 changes: 108 additions & 1 deletion .github/workflows/loristest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,114 @@ env:
EEG_VIS_ENABLED: 'true'

jobs:
build:
api:
runs-on: ubuntu-latest
env:
DB_DATABASE: LorisTest
DB_USER: SQLTestUser
DB_PASSWORD: TestPassword
LORIS_DB_CONFIG: project/config.xml
DOCKER_WEB_SERVER: http://localhost:8000/
strategy:
fail-fast: false
matrix:
php: ['8.1','8.2']
apiversion: ['v0.0.3', 'v0.0.4-dev']
steps:
- uses: actions/checkout@v2

- name: Set up MySQL
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }};' -uroot -proot
mysql -e "CREATE USER '${{env.DB_USER}}'@'localhost' IDENTIFIED BY '${{env.DB_PASSWORD}}'" -uroot -proot
mysql -e "GRANT UPDATE,INSERT,SELECT,DELETE,CREATE TEMPORARY TABLES ON ${{env.DB_DATABASE}}.* TO '${{env.DB_USER}}'@'localhost'" -uroot -proot
- name: Setup project/ directory
run: |
mkdir -p project/instruments
cp test/config.xml project/config.xml
cp test/test_instrument/NDB_BVL_Instrument_testtest.class.inc project/instruments/
cp -r raisinbread/instruments/* project/instruments/
sed -i 's/<sandbox>1<\/sandbox>/<sandbox>0<\/sandbox>/g' project/config.xml
sed -i 's/<adminUser>SQLTestUser<\/adminUser>/<adminUser>root<\/adminUser>/g' project/config.xml
sed -i 's/<adminPassword>TestPassword<\/adminPassword>/<adminPassword>root<\/adminPassword>/g' project/config.xml
sed -i 's/<host>db<\/host>/<host>localhost<\/host>/g' project/config.xml
cat project/config.xml
- name: Source default schema and Raisinbread
run: |
find SQL -name 0000-*.sql -exec sh -c "echo Sourcing {}; mysql ${{ env.DB_DATABASE}} -uroot -proot < {}" \;
find raisinbread/instruments/instrument_sql -name *.sql -exec sh -c "echo Sourcing {}; mysql ${{ env.DB_DATABASE}} -uroot -proot < {}" \;
find raisinbread/RB_files/ -name *.sql -exec sh -c "echo Sourcing {}; mysql ${{ env.DB_DATABASE}} -uroot -proot < {}" \;
- name: Source instrument schemas
run: |
find raisinbread/instruments/instrument_sql -name 0000-*.sql -exec sh -c "echo Sourcing {}; mysql ${{ env.DB_DATABASE}} -uroot -proot < {}" \;
echo Sourcing test/test_instrument/testtest.sql
mysql ${{ env.DB_DATABASE}} -uroot -proot < test/test_instrument/testtest.sql
- name: Set LORIS base path
run: |
echo UPDATE Config SET VALUE=\'`pwd`/\' WHERE ConfigID IN \(SELECT ID FROM ConfigSettings WHERE Name=\'base\'\)
echo UPDATE Config SET VALUE=\'`pwd`/\' WHERE ConfigID IN \(SELECT ID FROM ConfigSettings WHERE Name=\'base\'\) | mysql ${{env.DB_DATABASE}} -uroot -proot
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: zip, php-ast

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Composer cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install package dependencies
# We only need to install protobuf-compiler
# Other deps were added to fix an apt dependency issue introduced by a new github Ubuntu image
# (see https://github.com/actions/runner-images/blob/releases/ubuntu22/20230305/images/linux/Ubuntu2204-Readme.md)
# that updated the list of installed apt packages/apt repositories. That issue may disappear in future Ubuntu images.
run: |
sudo apt install -y imagemagick-6-common libmagickcore-6.q16-6 libmagickwand-6.q16-6 \
libprotobuf-dev libprotobuf23 libprotoc23 protobuf-compiler
cd modules/electrophysiology_browser/jsx/react-series-data-viewer/
protoc protocol-buffers/chunk.proto --js_out=import_style=commonjs,binary:./src/
- name: Install composer dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Build LORIS
run: make dev

- name: Start PHP Web Server
run: php -S localhost:8000 -t htdocs/ htdocs/router.php 2>error_log &

- name: Test server
run: |
sleep 1
curl -v http://localhost:8000
- name: Run Test Suite
run: |
vendor/bin/phpunit --configuration test/phpunit.xml --testsuite LorisAPITests --group api-${{ matrix.apiversion }}
- name: Print Error Logs
if: always()
run: cat error_log

docker:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class ProjectRecordingsRowProvisioner extends DBRowProvisioner
*/
function __construct(\Project $project, \DateTime $since)
{
// NOTE: we use string concatenation instead of a bind parameter for
// the $since parameter. PDOStatement->bindValues converts the parameter to
// a string. Timestamp > '0' is either a warning or exception depending
// on SQL configuration, (Timestamp > 0 is correct). The string concatenation
// ensures that it remains an int.
parent::__construct(
'
SELECT
Expand Down Expand Up @@ -65,12 +70,11 @@ class ProjectRecordingsRowProvisioner extends DBRowProvisioner
c.Active = \'Y\' AND
s.Active = \'Y\' AND
project.Name = :v_projectname AND
f.InsertTime > :v_time
f.InsertTime > ' . intval($since->getTimestamp()) . '
ORDER BY f.InsertTime ASC
',
[
'v_projectname' => $project->getName(),
'v_time' => $since->getTimestamp(),
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/api/php/views/visit/instrument_0_0_4_dev.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Instrument_0_0_4_Dev
$instrumentname = $this->_instrument->testName;
$instrumentdata = $this->_instrument->getInstanceData();

$isDDE = strpos($instrumentdata['CommentID'], 'DDE_') === 0;
$isDDE = strpos($this->_instrument->getCommentID() ?? '', 'DDE_') === 0;

$meta = [
'Candidate' => $this->_timepoint->getCandID(),
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiAuthenticatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class LorisApiAuthenticatedTest extends LorisIntegrationTest
*/
public function setUp(): void
{
$this->skipSelenium = true;
parent::setUp();

$this->_version = 'v0.0.4-dev';
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiAuthenticated_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class LorisApiAuthenticated_v0_0_3_Test extends LorisIntegrationTest
*/
public function setUp(): void
{
$this->skipSelenium = true;
parent::setUp();

$this->_version = 'v0.0.3';
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiCandidatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiCandidatesTest extends LorisApiAuthenticatedTest
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiCandidates_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiCandidates_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiDicomsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiDicomsTest extends LorisApiAuthenticatedTest
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiDicoms_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiDicoms_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiImagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiImagesTest extends LorisApiAuthenticatedTest
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiImages_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiImages_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiInstrumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiInstrumentsTest extends LorisApiAuthenticatedTest
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiInstruments_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiInstruments_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiLoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiLoginTest extends LorisApiAuthenticatedTest
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiLogin_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiLogin_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
6 changes: 4 additions & 2 deletions raisinbread/test/api/LorisApiProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiProjectsTest extends LorisApiAuthenticatedTest
{
Expand Down Expand Up @@ -742,14 +743,15 @@ public function testGetProjectsRecordings(): void
'headers' => $this->headers
]
);
$body = $response->getBody()->getContents();

$this->assertEquals(200, $response->getStatusCode());
// Verify the endpoint has a body
$body = $response->getBody();
$this->assertNotEmpty($body);

$projectsRecordingsArray = json_decode(
(string) utf8_encode(
strstr($response->getBody()->getContents(),"{")
strstr($body,"{")
),
true
);
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiProjects_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiProjects_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiRecordingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiRecordingsTest extends LorisApiAuthenticatedTest
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiRecordings_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiRecordings_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiSitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @author Xavier Lecours <xavier.lecours@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiSitesTest extends LorisApiAuthenticatedTest
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiSites_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @author Xavier Lecours <xavier.lecours@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiSites_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiVisitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.4-dev
*/
class LorisApiVisitsTest extends LorisApiAuthenticatedTest
{
Expand Down
1 change: 1 addition & 0 deletions raisinbread/test/api/LorisApiVisits_v0_0_3_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
* @group api-v0.0.3
*/
class LorisApiVisits_v0_0_3_Test extends LorisApiAuthenticated_v0_0_3_Test
{
Expand Down
20 changes: 14 additions & 6 deletions test/integrationtests/LorisIntegrationTest.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ abstract class LorisIntegrationTest extends TestCase
protected $DB;
protected $url;
protected $factory;

/**
* Allows subclasses that don't depend on Selenium to skip the Selenium
* WebDriver creation and login. (ie. API tests that use curl instead
* of selenium.)
*/
protected $skipSelenium = false;
/**
* A valid password to use for login tests.
*/
Expand Down Expand Up @@ -134,13 +141,14 @@ abstract class LorisIntegrationTest extends TestCase
['args' => ['-headless']]
);
}
if ($this->skipSelenium == false) {
$this->webDriver = RemoteWebDriver::create(
$selenium_url,
$desired_capabilities
);

$this->webDriver = RemoteWebDriver::create(
$selenium_url,
$desired_capabilities
);

$this->login("UnitTester", $this->validPassword);
$this->login("UnitTester", $this->validPassword);
}

if (extension_loaded('xdebug')
&& function_exists("xdebug_start_code_coverage")
Expand Down
5 changes: 4 additions & 1 deletion test/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
<directory>./unittests/</directory>
</testsuite>

<testsuite name='LorisAPITests'>
<directory>../raisinbread/test/api/</directory>
</testsuite>

<testsuite name='LorisCoreIntegrationTests'>
<directory>./integrationtests/</directory>
</testsuite>

<testsuite name='LorisModuleIntegrationTests'>
<directory>../raisinbread/test/api/</directory>
<directory>../modules/api/test/</directory>
<directory>../modules/acknowledgements/test/</directory>
<directory>../modules/brainbrowser/test/</directory>
Expand Down

0 comments on commit 1cd5f07

Please sign in to comment.