Skip to content

Instantly share code, notes, and snippets.

@sveneisenschmidt
Last active October 11, 2018 10:45
Show Gist options
  • Save sveneisenschmidt/02c98a4a416ec8f3610ec6409e16393e to your computer and use it in GitHub Desktop.
Save sveneisenschmidt/02c98a4a416ec8f3610ec6409e16393e to your computer and use it in GitHub Desktop.
[Draft] Parallel execution of CodeceptJS tasks

Idea 1

Introduce chunking to run-multiple

A first step is to introduce file base chunking to run-multiple. Technically we will do
a dynamic expansion of configuration to generate (n) run groups base one the chunks configured.

Context Files:

  • codecept.json
  • features/example1_test.js
  • features/example2_test.js
  • features/example3_test.js
  • features/example4_test.js
  • features/example5_test.js

Input

File: codecept.json

{
  "tests": "./featutres/*_test.js",
  "multiple": {
    "group1": {
      "chunks": 2,
      "browsers": ["chrome", { "browser": "firefox"}]
    },
    "group2": {
      "browsers": ["chrome", { "browser": "firefox"}]
    }
  }
}

Output

Object: Configuration object inside CodeceptJS

{
  "tests": "./featutres/*_test.js",
  "multiple": {
    "group1_chunk1": {
      "tests": "{features/example1_test.js,features/example2_test.js,features/example3_test.js}",
      "browsers": ["chrome", { "browser": "firefox"}]
    },
    "group1_chunk2": {
      "tests": "{features/example3_test.js,features/example4_test.js}",
      "browsers": ["chrome", { "browser": "firefox"}]
    },
    "group1": {
      "browsers": ["chrome", { "browser": "firefox"}]
    }
  }
}

To consider

  • If grep is set, chunking needs to grep files first and then run the chunking algorhytmn.

Idea 2

Introduce chunking to run-multiple

Based on Idea 1 a step further is to not only introduce file base chunking to run-multiple but also enable the user to configure the algorhytm used for chunking. Technically we will do a dynamic expansion of configuration to generate (n) run groups based on the chunks configured plus we enable the user to pass a object instead of an numeric value to specify the chunk algorhytm.

Context Files:

  • codecept.json
  • features/example1_test.js
  • features/example2_test.js
  • features/example3_test.js
  • features/example4_test.js
  • features/example5_test.js

Input

File: codecept.json

{
  "tests": "./featutres/*_test.js",
  "multiple": {
    "group1": {
      "chunks": {
        "count": 2,
        "type": "file"
      },
      "browsers": ["chrome", { "browser": "firefox"}]
    },
    "group2": {
      "browsers": ["chrome", { "browser": "firefox"}]
    }
  }
}

Output

Object: Configuration object inside CodeceptJS

{
  "tests": "./featutres/*_test.js",
  "multiple": {
    "group1_chunk1": {
      "tests": "{features/example1_test.js,features/example2_test.js,features/example3_test.js}",
      "browsers": ["chrome", { "browser": "firefox"}]
    },
    "group1_chunk2": {
      "tests": "{features/example3_test.js,features/example4_test.js}",
      "browsers": ["chrome", { "browser": "firefox"}]
    },
    "group1": {
      "browsers": ["chrome", { "browser": "firefox"}]
    }
  }
}

To consider

  • If grep is set, chunking needs to grep files first and then run the chunking algorhytmn.

Chunk algorhytmns

(All chunk algorhytmus work as file chunks as we, for now, only parallelize based on files via config.tests.)

  • file (default) - Generates chunks based on the total count of files, then distributes them evenly to file chunks.
  • feature - Scans all files and calculates the count of features, then distributes them evenly to file chunks.
  • scenario - Scans all files and calculates the count of scenarios, then distributes them evenly to file chunks.
  • dynamic - Runs once the whole suite in file mode, writes execution times of all files to a meta file, next run chunks are then created absed on the previous execution times of all files.

Idea 3

Introduce parallelization without chunking

  • A proper evolution of chunking is to enable real parallelization in both run and run-multiple commands.
  • A intermediate step is also possible by enabling chunking for run commands but translation it to a run-multiple command.
  • Although this is open to confusion for the user which would make combining run and run-multiple another logical step.
@dhairyathakker25
Copy link

"gherkin": {
"features": "./features/*.feature",
"steps": [
"./step_definitions/steps.js"
]
},
"multiple": {
"parallel": {
"chunks": {
"type":"feature",
"count":2
}
},
"browsers":["chrome"]
}

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