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

Support for PHP sub-processes #233

Closed
akserikawa opened this issue Nov 21, 2022 · 6 comments
Closed

Support for PHP sub-processes #233

akserikawa opened this issue Nov 21, 2022 · 6 comments

Comments

@akserikawa
Copy link

akserikawa commented Nov 21, 2022

Is there a way to share DB state between PHP main and sub-processes?

Currently, the class I want to test does something like this:

  1. Create entity in main process
  2. Edit that entity from a PHP sub-process via Symfony/Process component.

I would like to test that the result in DB matches what I expect once both steps finish.

Problem is the sub-process cannot retrieve the entity created in the main one.

ps: Note the sub-processes run asynchronously.

class A
{
    public function methodToTest()
    {
        // ...create entity in Database via it's entity repository
        
        $process = new Process(['bin/console', 'app:edit-entity', '--entity-id', $entity->getId()]);

        $process->start();
    }
}


class EditEntityCommand extends Command
{
    // ...
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
           $entityId = intval($input->getOption('entity-id'));

            $entityRepository = $this->entityManager->getRepository(Entity::class);
            $entity = $entityRepository->find($entityId);
            
            // -> ERROR: $entity is always null
    }
}

Any ideas on how to solve this? Is there a way to retrieve the changes in the entity?

@dmaicher
Copy link
Owner

Also see #66

Currently this bundle requires everything to be run in the same php process so that the same PDO instance is used and the transaction logic works.

Wondering why you need to edit the entity in a different php process?

@akserikawa
Copy link
Author

akserikawa commented Nov 21, 2022

Thanks for the fast answer!
Actually my use case is a bit more complicated than the example I provided.
I'm creating/editing a long list of entities at once and I need to run parallel processes due to performance issues. Because the editing part involves updating the actual entity + sending messages to different queues via AMQP.

From #66 I tried setting StaticDriver::setKeepStaticConnections(true); in my test case without success.

There is no way to solve this ATM then?

@dmaicher
Copy link
Owner

There is no way to solve this ATM then?

Yeah as of now this is impossible.

I would maybe instead look into solving those performance issues? Do you run your tests in "no-debug" mode for the Symfony kernel?

Doing this in sub-processes seems very exotic 😊

@akserikawa
Copy link
Author

akserikawa commented Nov 21, 2022

Sadly I currently don't have an option other than running parallel processes.
Updating thousands of records at once every minute and having to serialize each record and publish it to different queues via 3rd party API (each message takes ~140ms) would take more time than the mandatory minute timeframe.

Doing this in sub-processes seems very exotic blush

I agree, exotic solution for a bit exotic use case. And PHP does not help much here either :')

I'm now considering not using this bundle for this test case in particular and let the test case persist the data to the DB.
I'll have to clean up all records manually after that.

Thanks for your time though. Have a good day!

@dmaicher
Copy link
Owner

I'm now considering not using this bundle for this test case in particular and let the test case persist the data to the DB.
I'll have to clean up all records manually after that.

Yeah then this is the only way currently indeed

@dmaicher
Copy link
Owner

Closing as its the same issue as #66

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