lundi 22 février 2021

how to run paratest with multiple database

I am trying to use Paratest for my application.

My tests fail because of race-conditions and DEADLOCKS because they all use the same database.

Thus, I would like to create one database per process. In the docs, they mention this:

https://github.com/paratestphp/paratest/tree/2.2.0#test-token enter image description here

So I figured that getenv('TEST_TOKEN') is an integer value of a process. I have now created 8 MySql databases and seeded each, for each exists a connection in config/database.php from testdb_1 to testdb_8.

How do I change the connection for each test?

I tried this:

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;

    public function setUp()
    {
        parent::setUp();

        if (getenv('TEST_TOKEN') !== false) {  // Using paratest
            $this->connection = 'testdb_' . getenv('TEST_TOKEN');

            \DB::setDefaultConnection($this->connection );
        }

    }

}

but its not switching the database

Aucun commentaire:

Enregistrer un commentaire