2

I have an automated test setup written in javascript using jasmine and executing tests in parallel. Tests are executed using the following command:

protractor-flake --max-attempts=2 -- ./config/configfile.js --suite $SUITE "$@";

Inside the config file we set up all jasmine reporters, lists of all the test suites but also other prerequisites such as a class providing information about all the different feature flags that are on or off depending on the environment. The feature flags are fetched using an api call which happens in a method in configfile.js just before the tests are executed. I have tried creating a singleton and return the same instance but either i am doing something wrong or every new thread/process will create a new instance even if it's a singleton. Bellow is a simplified version of the singleton class.

class FeatureFlagConfiguration {

 async getFlags() {
     if (FeatureFlagConfiguration.instance === undefined) {
         const client = new Client();
         this.flags = await client.getFlags();
         this.moreInfo = await client.getMoreInfo();
         FeatureFlagConfiguration.instance = this;
         Object.freeze(FeatureFlagConfiguration.instance);
     }
 }

 evaluateFlags() {
     ...
 }


 isFeatureFlagEnabled() {
     ...
 }
}
module.exports = new FeatureFlagConfiguration();
Jan
  • 338
  • 3
  • 18

1 Answers1

0

Try using a global variable instead, as suggested here: https://stackoverflow.com/a/1479341/3482730

So probably something like:

class FeatureFlagConfiguration {

 async getFlags() {
     if (FeatureFlagConfiguration.instance === undefined) { // prob not needed
         const client = new Client();
         this.flags = await client.getFlags();
         this.moreInfo = await client.getMoreInfo();
         FeatureFlagConfiguration.instance = this;  // prob not needed
         Object.freeze(FeatureFlagConfiguration.instance); // prob not needed
     } // prob not needed
 }

 evaluateFlags() {
     ...
 }


 isFeatureFlagEnabled() {
     ...
 }
}

const featureFlagConfigurationInstance = new FeatureFlagConfiguration();

module.exports = featureFlagConfigurationInstance;
lezhumain
  • 387
  • 2
  • 8