Coder Social home page Coder Social logo

Comments (20)

powellblyth avatar powellblyth commented on May 10, 2024 2

I just improved my life a lot by altering the DB_USERNAME
in .env.testing to be root....

DB_USERNAME=root

from sail.

nat-mystudiosessions avatar nat-mystudiosessions commented on May 10, 2024 2

@driesvints Thanks for your reply. Here is the repo https://github.com/nat-mystudiosessions/sail-issue-112

I get the error running the command sail test --parallel --recreate-databases.

However, if I update the default .env variable from DB_USERNAME=sail to DB_USERNAME=root as @powellblyth suggested the error does not occur.

Since this is a new empty project it needs the --recreate-databases flag to show the error. In the project I am working on I have written database tests, so I get the error even without the flag. Thanks for checking this out. Please let me know if I can help further.

from sail.

bjuppa avatar bjuppa commented on May 10, 2024 1

Here's a proposed solution for parallel testing in Sail, now that we can leave my unfortunate typos 😄 above behind us:

Setting env DB_USERNAME to root directly in the sail test command proxy enables creating/dropping databases during parallel testing.

This is where the proxy is defined:

sail/bin/sail

Lines 126 to 129 in c54ad51

docker-compose exec \
-u sail \
"$APP_SERVICE" \
php artisan test "$@"

...and this is the line to add:

-e DB_USERNAME=root \

After that change, you can run sail test --parallel --recreate-databases successfully!

As Sail is meant to be a local dev environment I don't think it hurts running the tests with another db user than what's actually specified in .env. Unless you have some test that explicitly tests db user permissions... which I believe is extremely unlikely 😆

And here's the repo with reproduction of the problem we're solving: https://github.com/bjuppa/sail-issue-112

from sail.

powellblyth avatar powellblyth commented on May 10, 2024

Oo I'm investigating this exact same issue on my end.

I've altered my .env.testing environment so i can run the test from my host, but I get the exact same error. The issue may not be inside Sail

from sail.

nat-mystudiosessions avatar nat-mystudiosessions commented on May 10, 2024

Cool @powellblyth! I didn't see reference to a root user even being created while I was digging around the docker files, so I was a bit lost. It's nice to know it's created in the background, though I'm sure someone else will run into the same problem and maybe they can find this post and save them a day of head scratching. Thanks for the help.

from sail.

driesvints avatar driesvints commented on May 10, 2024

Heya, thanks for reporting.

I'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new sail-issue-112 --github="--public"

After you've posted the repository, I'll try to reproduce the issue.

Thanks!

from sail.

driesvints avatar driesvints commented on May 10, 2024

@nat-mystudiosessions you did not create the repo with the command I posted above. Please recreate the repo with the exact command from above.

from sail.

nat-mystudiosessions avatar nat-mystudiosessions commented on May 10, 2024

@driesvints Ok. I tried the command first and got an error (I'm developing via WSL). I will read up on the GitHub CLI tool and try again (haven't used it before).

from sail.

driesvints avatar driesvints commented on May 10, 2024

@nat-mystudiosessions actually just committing the skeleton separate from your specific changes is the most important thing.

from sail.

nat-mystudiosessions avatar nat-mystudiosessions commented on May 10, 2024

@driesvints Ok, I was a little confused because I actually didn't change anything. The error occurs with a fresh Laravel install, that is all that is in the repo. Changing the DB_USERNAME env value from sail to root makes the problem go away, but since sail is the default DB_USERNAME it will likely throw people off the first time they try parallel testing. I'm not sure if answer is a bug fix or just a note in the docs, something like If you're using parallel testing, be sure your testing env file DB_USERNAME is set to root or else the testing process won't have the proper permissions to drop or create the necessary testing tables. 🙂

from sail.

driesvints avatar driesvints commented on May 10, 2024

I can run parallel testing just fine with the env values set by sail (including the sail username). Please post a way for me to reproduce the issue, otherwise I can't help out sorry.

from sail.

bjuppa avatar bjuppa commented on May 10, 2024

Hi, I ran into the same issue and created a repo with a reproduction according to instructions ☝️ and documented steps to reproduce in the readme:

https://github.com/bjuppa/sail-issue-112

I guess the problem is that tests are run with the DB_USERNAME from .env... and in Sail's MySQL this user has no permission to drop or create databases. Only the root db user has this permission.

So, while you can indeed get the tests to run in parallel by setting DB_USERNAME to root, anyone cloning a Laravel project where DB_USERNAME is set to something other than root in .env.example will run into problems.

@driesvints, what if Sail could give create+drop database permissions to the DB_USERNAME user after creating the MySQL instance?

from sail.

driesvints avatar driesvints commented on May 10, 2024

@bjuppa parallel testing isn't supported for Dusk.

from sail.

bjuppa avatar bjuppa commented on May 10, 2024

@bjuppa parallel testing isn't supported for Dusk.

Ah, that's a shame! It seems to be such a small change to get it working, and it saves so much time to run tests in parallel while developing 😄

If I can get parallel testing working again with Sail, will you consider a PR?

I've been using parallel testing with Sail since I started work on my app in September and it's been working fine up until I rebuilt the docker images.

from sail.

powellblyth avatar powellblyth commented on May 10, 2024

Hey @driesvints , you asked for an example. sorry I didn't see that.
https://github.com/powellblyth/sail-issue-112

The failing test is the example test. I didn't bother actually writing a test in it because it happens when the user factory is triggered.

If we are all doing something wrong, I'd welcome a PR ;o)

from sail.

driesvints avatar driesvints commented on May 10, 2024

If I can get parallel testing working again with Sail, will you consider a PR?

It's literally impossible due to chrome not supporting it.

from sail.

powellblyth avatar powellblyth commented on May 10, 2024

for my example above, this is my .env (It's an out-of-the-box copy of example)
This is running on Intel Mac on Big Sur in case that's relevant. Latest version of docker

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:yg3jwRpCiRo3D0MwrZDkpuXJ5dyLgZWLqv7DiawS134=
APP_DEBUG=true
APP_URL=http://sail-issue-112.test

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=sail_issue_112
DB_USERNAME=sail
DB_PASSWORD=password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=memcached

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

from sail.

bjuppa avatar bjuppa commented on May 10, 2024

If I can get parallel testing working again with Sail, will you consider a PR?

It's literally impossible due to chrome not supporting it.

Would that be parallel testing with Sail + Dusk?

What I'm trying to do is just get sail test --parallel working. And it already does in my app, as long as I do sail up with a DB_USERNAME other than root, and then switch it to root in .env before running sail test --parallel

from sail.

bjuppa avatar bjuppa commented on May 10, 2024

Sorry! I realize I confused everyone! I meant to write Sail above in my first comment, not Dusk 😬 This issue has nothing to do with Dusk, I'm sorry!

from sail.

bjuppa avatar bjuppa commented on May 10, 2024

I've updated my first comment above ☝️ to be correct, will you please read it again in this new light? 🙏

#112 (comment)

from sail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.