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

Laravel example: Transactions not working #34

Closed
spawnia opened this issue Jan 31, 2018 · 1 comment
Closed

Laravel example: Transactions not working #34

spawnia opened this issue Jan 31, 2018 · 1 comment

Comments

@spawnia
Copy link

spawnia commented Jan 31, 2018

First of all, thanks for this package - it has helped me a lot.

Whats the problem?

I tried using the hooks as described in the Laravel example project. I was quickly able to get them to run, but no matter what i tried, the transactions did not work. A search in the issues revealed that this already happened to someone before, as described in #15

Proposal

What i require is a way of resetting the changes made by requests that the API tests generate. The only way i could think of was migrating the whole database before each testrun, like this:

Hooks::beforeAll(function (&$transaction) {
    \Illuminate\Support\Facades\Artisan::call('migrate:refresh', ['--seed' => true]);
});

Is there a better way? My main motivation behind this is achieving better test isolation through something like transactions. If this is the only way, maybe include the snippet above in the Laravel example - together with a short disclaimer explaining the limitations of transactions.

@ddelnano
Copy link
Owner

ddelnano commented Feb 3, 2018

Sorry for the late response, I've been traveling. So as I said in #15 there isn't a better way to do things in a simple way. That thread explains the why but it can be still hard to picture what makes it challenging. So let's look at a overview of how things works.

screen shot 2018-02-03 at 12 49 36 pm

In order to implement what you want you would need some type of mysql connection multiplexing. It would look something like this.

screen shot 2018-02-03 at 1 15 12 pm

There are mysql proxies like proxysql. However, it will disable connection multiplexing on transactions because in a normal situation that would be very bad.

I agree with you that having a way of resetting the application state quickly on a single test would be very beneficial. When I was actively working on a project that was using Dredd, I was trying to solve this isolation problem a different way. I wrote up on it in apiaryio/dredd#536 so give that a look. It's an unresolved issue and what I was trying to implement is probably much more complexity than what you are looking for. In addition to the test isolation, I wanted to be able to parallelize the execution of Dredd tests.

Anyway, the short answer is there is no out of the box or easy solution. However, since I'm interested and I have been looking into proxysql I'm going to see if I can "patch" it to always multiplex connections. Even if that ends up working, I wouldn't advocate that as a solution for an average Dredd / php hooks user due to the increased complexity.

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