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

Bad Laravel Example. Impossible to get access to uncommited data from another transaction #1470

Closed
imissyouso opened this issue Aug 15, 2019 · 3 comments

Comments

@imissyouso
Copy link

imissyouso commented Aug 15, 2019

Seems there is a bug https://github.com/ddelnano/dredd-hooks-php/wiki/Laravel-Example
Look on tests/dredd/hooks/hookfile.php

...
Hooks::beforeEach(function (&$transaction) use ($app) {
    $app->make('db')->beginTransaction();
});

Hooks::afterEach(function (&$transaction) use ($app) {
    $app->make('db')->rollback();
});
...

does it make sense to make HTTP transaction isolation using such approach?
This code executes inside of bin/dredd-hooks-php process therefore it has own database connection but at the same time API server under test has another connection and doesn't see any uncomitted data of bin/dredd-hooks-php process. So how it should work? May be I should use something like 'Read uncommitted' isolation level of postgres to make it workable? :/

Expected behavior

  1. create test data and save to database inside of before hook
  2. run test
    2.1 request data from the API server, server should find and return just created data inside of before hook
    2.2 pass the test if data is correct
  3. cleanup database

In Laravel example it made by using beginTransaction/rollback inside of beforeAll/afterAll hooks, but seems it wrong.

What is in your dredd.yml?

color: true
dry-run: null
hookfiles: /srv/tests/dredd/bootstrap.php
language: /srv/vendor/ddelnano/dredd-hooks-php/bin/dredd-hooks-php
require: null
# null because I use my server which already works on 80 port
server: null
server-wait: 3
init: false
custom: {}
names: false
only: []
reporter: [dot]
output: []
header: []
sorted: false
user: test:uy5elx0pCYYZZucsoC06TAMq3KewM9
inline-errors: false
details: false
method: []
loglevel: debug
path: []
hooks-worker-timeout: 5000
hooks-worker-connect-timeout: 5000
hooks-worker-connect-retry: 500
hooks-worker-after-connect-wait: 500
hooks-worker-term-timeout: 5000
hooks-worker-term-retry: 500
hooks-worker-handler-host: 127.0.0.1
hooks-worker-handler-port: 61321
config: ./dredd.yml
blueprint: swagger.yaml
# I run it inside of a docker
endpoint: 'host.docker.internal:80'

What's your dredd --version output?

dredd v11.2.18 (Linux 4.9.93-linuxkit-aufs; x64)
@honzajavorek
Copy link
Contributor

I'm afraid we're not so experienced here with how db transactions work in Laravel exactly. It might be better idea to file this issue at https://github.com/ddelnano/dredd-hooks-php directly so @ddelnano or other users of the PHP hooks can easily look it up and answer.

@ddelnano
Copy link
Contributor

This is definitely a known issue (see ddelnano/dredd-hooks-php#34). The example should probably use database migrations rather than transactions (so it can start with a clean slate for every test).

@honzajavorek
Copy link
Contributor

I'll close this issue then. @ddelnano Thanks! 🙏

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

No branches or pull requests

3 participants