【问题标题】:Running unit tests after starting elasticsearch启动 elasticsearch 后运行单元测试
【发布时间】:2018-04-10 18:21:32
【问题描述】:

我已经在一个用于运行 Jenkins 的 EC2 实例上下载并设置了 elasticsearch。我想使用 Jenkins 运行一些使用本地弹性搜索的单元测试。

我的问题是我还没有找到如何在本地启动弹性搜索并在之后运行测试的方法,因为脚本在启动 ES 后没有继续,因为作业没有被杀死或任何东西。

我可以通过 SSH 手动启动 ES,然后构建一个只有单元测试的项目来做到这一点。但是,我想自动启动 ES。

关于如何实现这一目标的任何建议?我现在尝试使用单个“Execute shell”块和两个“Execute shell”块。

【问题讨论】:

    标签: bash elasticsearch jenkins


    【解决方案1】:

    这是因为您以阻塞方式启动 elasticsearch 命令。这意味着命令将等待弹性搜索服务器关闭。詹金斯继续等待。

    您可以使用以下命令

    ./elasticsearch 2>&1 >/dev/null &
    

    nohup ./elasticsearch 2>&1 >/dev/null &
    

    它将以非阻塞方式运行命令。

    您还可以添加小延迟以允许弹性搜索服务器启动

    nohup ./elasticsearch 2>&1 >/dev/null &; sleep 5
    

    【讨论】:

    • 2>&1 >/dev/null & 部分有什么作用?由于某种原因,即使我设置了睡眠,我的测试也无法连接到 Elasticsearch。这是我得到的错误:requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9200): Max retries exceeded with url: /test-events (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7efedc1dbd68>: Failed to establish a new connection: [Errno 111] Connection refused',)) 编辑:我不得不增加睡眠
    • 2>&1 将标准错误重定向到标准输出。更多信息在这里cyberciti.biz/faq/redirecting-stderr-to-stdout
    猜你喜欢
    • 2019-07-15
    • 1970-01-01
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    相关资源
    最近更新 更多