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

Add support for paratest #11148

Open
4 tasks done
beerbohmdo opened this issue Feb 16, 2024 · 2 comments
Open
4 tasks done

Add support for paratest #11148

beerbohmdo opened this issue Feb 16, 2024 · 2 comments

Comments

@beerbohmdo
Copy link
Contributor

beerbohmdo commented Feb 16, 2024

Description

I want to use paratest, but I had sometimes weird issues because of the shared cache folder.

Paratest provides a TEST_TOKEN environment variable.

I just tried to append this to the TEMP_FOLDER and SS_DATABASE_PREFIX and all my issues went away. I currently hardcoded it to TempFolder and TempDatabase class, because I am not really sure how I seed them dynamically.

As the TEMP_FOLDER is defined really early in the code and loaded by composer autoloader its hard to put custom code before that ...

Any suggestion for a better way to handle this are welcome.

Additional context or points of discussion

My hacky and dirty way:

--- /tmp/silverstripe-framework/src/ORM/Connect/TempDatabase.php	2024-02-16 12:27:07.158611326 +0100
+++ src/ORM/Connect/TempDatabase.php	2024-02-16 11:29:26.590707137 +0100
@@ -57,6 +57,11 @@
     protected function isDBTemp($name)
     {
         $prefix = Environment::getEnv('SS_DATABASE_PREFIX') ?: 'ss_';
+
+        if (($token = getenv('TEST_TOKEN')) !== false) {
+            $prefix .= $token . '_';
+        }
+
         $result = preg_match(
             sprintf('/^%stmpdb_[0-9]+_[0-9]+$/i', preg_quote($prefix ?? '', '/')),
             $name ?? ''
@@ -198,6 +203,11 @@
         // Create a temporary database, and force the connection to use UTC for time
         $dbConn = $this->getConn();
         $prefix = Environment::getEnv('SS_DATABASE_PREFIX') ?: 'ss_';
+
+        if (($token = getenv('TEST_TOKEN')) !== false) {
+            $prefix .= $token . '_';
+        }
+
         do {
             $dbname = strtolower(sprintf('%stmpdb_%s_%s', $prefix, time(), rand(1000000, 9999999)));
         } while ($dbConn->databaseExists($dbname));
--- /tmp/silverstripe-framework/src/Core/TempFolder.php	2024-02-16 12:27:07.142611530 +0100
+++ src/Core/TempFolder.php	2024-02-16 11:22:52.855885901 +0100
@@ -54,6 +54,9 @@
             $user = 'unknown';
         }
         $user = preg_replace('/[^A-Za-z0-9_\-]/', '', $user ?? '');
+        if (($token = getenv('TEST_TOKEN')) !== false) {
+            $user .= '-' . $token;
+        }
         return $user;
     }

Validations

  • You intend to implement the feature yourself
  • You have read the contributing guide
  • You strongly believe this feature should be in core, rather than being its own community module
  • You have checked for existing issues or pull requests related to this feature (and didn't find any)
@beerbohmdo beerbohmdo changed the title Support for paratest Add support for paratest Feb 16, 2024
@emteknetnz
Copy link
Member

emteknetnz commented Feb 20, 2024

@beerbohmdo
Copy link
Contributor Author

More directories which must be seeded 🙈

if ($token = getenv('TEST_TOKEN')) {
    Requirements::backend()->setCombinedFilesFolder('_combinedfiles' . $token);
    Config::modify()->set(TinyMCECombinedGenerator::class, 'filename_base', '_tinymce' . $token . '/tinymce-{name}-{hash}.js');
}

But this can be set inside a _config.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants