作为我工作的一部分,我正在开始使用特定论点的幻影.
这是在自定义的gitlab/gitlab-ci服务器上运行的,我目前没有使用容器,我想这会简化它.
我正在开始像这样的幻影:
- "timeout 300 phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /tmp/gastonjs.log &"
Run Code Online (Sandbox Code Playgroud)
然后我正在运行我的behat测试,然后我再次停止该过程:
- "pkill -f 'src/Client/main.js' || true"
Run Code Online (Sandbox Code Playgroud)
问题是当behat测试失败时,它不执行pkill并且测试运行等待phantomjs完成.我已经添加了超时300,但这意味着我现在仍然在等待2分钟后失败并且当测试仍然在运行时它们会变得足够慢时最终会停止它.
我还没有找到一种方法来运行某种运行后/清理命令,该命令也会在失败的情况下运行.
有一个更好的方法吗?我可以用gitlab-ci不关心它仍在运行的方式启动phantomjs吗?可能没有?
TL; 博士; - 在一个新线程中生成进程,&但是你必须确保该进程在成功和失败构建中被终止。
我用这个(有评论):
'E2E tests':
before_script:
- yarn install --force >/dev/null
# if there is already an instance running kill it - this is ok in my case - as this is not run very often
- /bin/bash -c '/usr/bin/killall -q lite-server; exit 0'
- export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d ':' | head -n1)
- export E2E_BASE_URL="http://$DOCKERHOST:8000/#."
# start the lite-server in a new process
- lite-server -c bs-config.js >/dev/null &
script:
# run the tests
- node_modules/.bin/protractor ./protractor.conf.js --seleniumAddress="http://localhost:4444/wd/hub" --baseUrl="http://$DOCKERHOST:8000" --browser chrome
# on a successfull run - kill lite server
- killall lite-server >/dev/null
after_script:
# when a test fails - try to kill it in the after_script. this looks rather complicated, but it makes sure your builds dont fail when the tests succeedes and the lite-server is already killed. to have a successfull build we ensure a non-error return code (exit 0)
- /bin/bash -c '/usr/bin/killall -q lite-server; exit 0'
stage: test
dependencies:
- Build
tags:
- selenium
Run Code Online (Sandbox Code Playgroud)
https://gist.github.com/rufinus/9ee8f04fc1f9248eeb0c73ad5360a006#file-gitlab-ci-yml-L7
正如所暗示的,基本上我的问题不是我无法终止该进程,而是运行我的测试脚本并且它在那时停止失败,导致死锁。
我已经在做一些与@Rufinus 的示例非常相似的事情,但它对我来说不起作用。可能有一些不同的事情,比如运行测试的不同方式或在 before_script 中启动它,这对我来说不是一个选择。
我确实找到了一种让它为我工作的方法,那就是防止我的测试运行程序停止执行进一步的任务。我设法通过“set +e”来做到这一点,然后存储退出代码(我之前尝试过这样做,但没有成功)。
这是我工作中的相关部分:
# Set option to prevent gitlab from stopping if behat fails.
- set +e
- "phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /dev/null &"
# Store the exit code.
- "./vendor/bin/behat -f progress --stop-on-failure; export TEST_BEHAT=${PIPESTATUS[0]}"
- "pkill -f 'src/Client/main.js' || true"
# Exit the build
- if [ $TEST_BEHAT -eq 0 ]; then exit 0; else exit 1; fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1261 次 |
| 最近记录: |