getgauge / gauge-ts

Typescript language plugin for Gauge
MIT License
31 stars 14 forks source link

unable to share state between scenarios when using parallel #139

Closed pwmcintyre closed 5 months ago

pwmcintyre commented 3 years ago

Describe the bug

when using --parallel flag, gauge seems to spawn multiple completely isolated processes.

where normally i might do some once-off BeforeSuite setup; this is no longer possible. Furthermore, there is no mechanism of sharing information between scenarios.

is there a way to share state between scenarios while using --parallel?

To Reproduce

1 — tests tests/steps.foo.ts

import { BeforeSuite, DataStoreFactory, Step } from 'gauge-ts'
import { ulid as idgen } from 'ulid'

export default class StepFoo {
  @BeforeSuite()
  public async BeforeSuite (): Promise<void> {
    const id = idgen()
    DataStoreFactory.getSuiteDataStore().put('id', id)
    console.log('@BeforeSuite', { id })
  }

  @Step('foo')
  public async step (): Promise<void> {
    const id: string = DataStoreFactory.getSuiteDataStore().get('id')
    console.log('@StepFoo', { id })
  }
}

2 — 2 specs: specs/foo.1.md

# scenario 1

## test 1

* foo

specs/foo.2.md

# scenario 2

## test 2

* foo

Output without parallel:

$ npx gauge run
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped
@BeforeSuite { id: '01F98B3Z17KWCRA3ZFM4JXKDR8' }
# scenario 1
  ## test 1     @StepFoo { id: '01F98B3Z17KWCRA3ZFM4JXKDR8' }
 ✔

# scenario 2
  ## test 2     @StepFoo { id: '01F98B3Z17KWCRA3ZFM4JXKDR8' }
 ✔

Successfully generated html-report to => /Users/petermcintyre/git/gauge-foo/reports/html-report/index.html

Specifications: 2 executed      2 passed        0 failed        0 skipped
Scenarios:      2 executed      2 passed        0 failed        0 skipped

Total time taken: 414ms

output with parallel

$ npx gauge run --parallel
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped
Executing in 2 parallel streams.
Incorrect value for enable_multithreading in property file. Cannot convert  to boolean.
Using default value false for property enable_multithreading.
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped
@BeforeSuite { id: '01F98B484ZGW9H2YAPFG556HSJ' }
[runner: 1] # scenario 1
[runner: 1]   ## test 1
@StepFoo { id: '01F98B484ZGW9H2YAPFG556HSJ' }
[runner: 1] 
[runner: 1] # scenario 2
[runner: 1]   ## test 2
@StepFoo { id: '01F98B484ZGW9H2YAPFG556HSJ' }
[runner: 1] 
@BeforeSuite { id: '01F98B48B7T2XYKP214MC093H4' }
Successfully generated html-report to => /Users/petermcintyre/git/gauge-foo/reports/html-report/index.html

Specifications: 2 executed      2 passed        0 failed        0 skipped
Scenarios:      2 executed      2 passed        0 failed        0 skipped

Total time taken: 3.857s

Expected behavior

both parallel and non-parallel to share the same @BeforeSuite and SuiteDataStore

I guess i was expecting regular NodeJS style single-threaded concurrency? 🤷

Desktop (please complete the following information):

Gauge version: 1.1.8
Commit Hash: b1501f4

Plugins
-------
html-report (4.0.12)
screenshot (0.0.1)
ts (0.1.0)

Additional context

BugDiver commented 3 years ago

Gauge's default behavior for Parallelisation is Multi Process. It launches multiple instances of the runner, so the state between these processes won't be shared. Gauge does support Threading-based Parallelisation, but that is only supported for the Languages like Java or CSharp (dotnet). Since NodeJs is only single-threaded, it won't be easy to achieve threading-based parallelization in this plugin. Al tough I'll try to spend some time and see if there are any work arounds.

pwmcintyre commented 5 months ago

@BugDiver NodeJS doesn't do parallelism, but it is great at concurrency.

I would really appreciate a "concurrent" option, to allow N>1 scenarios to run at the same time, which some might argue is the intent of the "parallel" option.

Specs can be executed in parallel to run the tests faster.

https://docs.gauge.org/execution.html?os=windows&language=javascript&ide=vscode#:~:text=Specs%20can%20be%20executed%20in%20parallel%20to%20run%20the%20tests%20faster.