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

Request - Share state between threads #413

Closed
FranciscoAAR opened this issue Aug 2, 2024 · 1 comment
Closed

Request - Share state between threads #413

FranciscoAAR opened this issue Aug 2, 2024 · 1 comment

Comments

@FranciscoAAR
Copy link

Hi, Prashant. I hope you're doing well.

Currently, sharing state between threads can be quite challenging because all threads run isolated from each other. Do you think it is possible to include a capability similar to Java’s ConcurrentHashMap to serve as a place to post a given variable or value visible to all running threads? This would greatly simplify some aspects of my testing.

Thank you very much for considering this request.

@prashant-ramcharan
Copy link
Owner

Hello, not sure if this would be in scope of this library.

The issue with sharing context between tests is that they are non deterministic. There's no guarantee to the order in which tests start / complete etc.. so you may find issues with race conditions and asserting the wrong thing etc..

However you can implement this yourself to try out:

    @CourgetteBeforeAll
    public static void setUp() {
       // start an in-memory database or any other type of persistence.
      inMemoryDB.create()
      inMemoryDB.save('XYZ', 123)
    }

    @CourgetteAfterAll
    public static void tearDown() {
      inMemoryDB.close()
    }
    @When("I retrieve the shared data for XYZ")
    public void retrieve_data() {
        var sharedDataFromDB = inMemoryDB.get('XYZ');
        assertEquals(sharedDataFromDB, 123);
    }

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

No branches or pull requests

2 participants