Composer script to start a background process, whose lifetime is bound to that of the Composer script - composer-php

I've started experimenting with Composer Scripts.
I have a project where there are "Functional tests" of the API endpoints. Running the whole test suite requires running the following commands in order:
composer install to install all required dependencies of the backend APIs
php yii server --test to start a lite server that is connected to the "test" MySQL database. The test server starts running on localhost:9000.
sh vendor/bin/phpunit --configuration tests/functional/phpunit.xml to run th actual tests. This last command triggers the execution of all test cases, most of which execute HTTP calls to the lite server, launched at step 2.
I would like to automate and "atomize" this 3 step process into a single Composer script that can be easily started, killed and restarted effortlessly.
Here's my current progress:
"scripts": {
"test-functional": [
"#composer install",
"php yii server --test",
"sh vendor/bin/phpunit --configuration tests/functional/phpunit.xml"
]
}
The problem is that the 2-nd command (php yii server --test) "steals" the terminal because PHPs built-in lite server requires the terminal to be open while the command is running. Killing the command kills the lite server as well. I tried suffixing the second step of the script with & which generally makes processes go in the background and not steal the terminal, but it seems this trick doesn't work for Composer Scripts. Any other workaround or possibility that I'm missing?
My final goal is to make the 3 steps execute in an atomic way, output the results of the tests and end the command, cleaning up everything (including killing the lite server, launched in step 2).

Related

Stripe CLI `listen` not quitting after exit

I've created a shell script to run my dev server, listen to stripe test hooks, and then exec my test scripts in firebase emulators.
npm run dev &
stripe listen -f http://0.0.0.0:5001/.../stripeWebhook &
firebase emulators:exec "npm run test" --import ./cypress/cypress/fixtures/firebase
This seems to work, but after it finishes the stripe process doesn't seem to exit and subsequent runs look like they're trying to process each stripe hook multiple times. How do I force the stripe CLI to stop listening?
The stripe listen command does not run in the background but rather streams the output to stdout. Therefore I think it will not behave properly running in a shell script, especially when combined with other commands. It is possible that your script is generating a listening process with each run and the event is being forwarded for each process.
I would stick to running stripe listen in a dedicated terminal session to ensure you get the expected behavior.

Run macOS Test Cases on the Jenkins Pipeline

Hi I have an macOS Application which needs to be configured for CI/CD purpose on the Jenkins.
I need to run the test cases before making the application available for the distribution or before creating a package file.
I am using the below mentioned command
xcodebuild -workspace xxx.xcworkspace -sdk macosx11.3 -scheme xxx -destination "platform=OS X,arch=x86_64" clean test
when I execute this command in the Jenkins it throws me an error
ERROR: The test runner encountered an error (Failed to establish communication with the test runner. If you believe this error represents a bug, please attach the result bundle at /Users/ec2-user/Library/Developer/Xcode/DerivedData/xxx-gkolnyonjdnyixfknefsjvbsyzia/Logs/Test/Run-xxx-2021.05.24_11-58-07-+0000.xcresult. (Underlying Error: Couldn’t communicate with a helper application. Try your operation again. If that fails, quit and relaunch the application and try again. The connection to service on pid 0 named com.apple.testmanagerd.control was invalidated.))
I need to make use of macOS itself to run as a simulator. As Jenkins runs as a Daemon on the ec-2 instance.
NOTE: NOT USING XCODE PLUGIN TO EXECUTE MY COMMANDS
Please help!!!
My MacOS system was a slave and I was running my scripts through the Linux server.
macOS was connected using the SSH earlier then this authentication method was required to be changed to access the UI of the Mac
Test cases running now
Based on observation, macOS Big Sur, Monterey, and probably subsequent versions no longer allow tests to be run through a SSH session. By changing the way Jenkins controller connects to the slave, you can prevent the command from being run through SSH.
The first way, Jenkins built-in, to do this and easiest is to use the JNLP method for agent communication. This will involve running a Jenkins agent on the slave machine that communicates with the Jenkins controller. In the end, the agent on the machine is running the test command rather than through a SSH session.
The second way is to build your own agent. It could be as simple as a file change trigger leading to a script executing. This is only necessary if for some reason the Jenkins slave is not able to connect to the Jenkins controller due to some networking constraints.

MariaDB clashing with MySQL on Travis-CI

I have a test suite that runs on Travis-CI and requires MariaDB (but it breaks on MySQL). The pre-test scripts call the mysql command, but run commands against MariaDB, as the command is the same for both.
echo "CREATE DATABASE test1" | mysql -u travis
The tests on worker v2.5.0 were passing just fine (https://travis-ci.org/stems/join-monster/jobs/256751422). However, the tests started running on a later version of the worker v2.9.3 and failing without any changes to the code (https://travis-ci.org/stems/join-monster/jobs/260001701). According to the system build information, this new version seems to be installing MySQL in addition to MariaDB. Now when I run my mysql command, it's running against MySQL instead of MariaDB and breaking the build.
I need either:
to go back to a previous version of the worker (can't find any info on how to do this in the Travis docs.
to specify that I want to run commands and connect to MariaDB, NOT MySQL.
to tell Travis to not install MySQL to avoid the clashing
Any of these solutions would be appreciated.
Fixed it by switching the Ubuntu version back to 12 rather than 14, which had become the new default.
In the .travis.yml
dist: precise

How to run selenium server in the background using windows batch script in Jenkins?

I am running protractor tests on a server machine through Jenkins. I need to start the selenium web driver before running the tests. i.e. "webdriver-manager start" and run the tests while the server is running and shut it down once tests are run. How do I do this using batch script?
I am using start, cmd commands in the batch file to achieve it but once the selenium server starts, I am unable to go back to the prompt unless I stop it.
How to I make it run in the background by staying in the same command prompt window rather than opening up the new command prompt window selenium server starts?
you should run webdriver-manager start as shell script.
Make sure
1 - Node.js installed on jenkins
2 - provide correct path to webdriver-manager

Is there a way to open an interactive Command Prompt from a service?

When I try to execute "vstest.console.exe" file in Jenkins CI (service mode), it responses
Error: Could not start test run for unit tests for Windows Store app:
Unit tests for Windows Store apps cannot be run from a service or non
interactive process. Please run unit tests from an interactive
process..
However it will be able to run successful if I execute the same command from a Command prompt.
So I want to ask if there is a way to open Command Prompt from a service such as Jenkins CI.
I have tried with "start ExecuteVSTest.bat /I /K /REALTIME" but the result is still the same.
I couldn't find a way to open Command Prompt from a service. However I am able to resolve the problem between Jenkins CI and "vstest.console.exe".
We just need to deploy Jenkins from the WAR file via Tomcat server instead of installing Jenkins service native package.
Since the Tomcat is running in the console mode so Jenkins CI won't have the same trouble when executing "vstest.console.exe" as when it run in service mode.

Resources