簡體   English   中英

Rails,Tire和CircleCI:在創建Tire-Searchable對象時運行rspec測試時出現Errno :: ECONNREFUSED錯誤

[英]Rails, Tire, and CircleCI: Getting a Errno::ECONNREFUSED error when running rspec tests when creating Tire-Searchable objects

我有一個使用CicleCI進行測試的項目,我正在嘗試將Tire集成到搜索功能中。 在本地,所有測試運行良好,沒有問題。 但是,當CircleCI運行測試時,我得到一個Errno::ECONNREFUSED : Connection refused - connect(2)錯誤。 我已經嘗試將tire.rb文件添加到config / initilizers:

if Rails.env.test?
  ENV['ELASTICSEARCH_URL'] = "http://circlehost:9200" # With and without this. 
  Tire.configure do
    url "http://circlehost:9200" # also tried localhost:9200, and 127.0.0.1:9200
  end
end

嘗試添加circle.yml文件,如下所示: httpscircle.yml

hosts:
    circlehost: 127.0.0.1

以及這些的任何組合。 現在我沒有想法,也不知道該怎么做。 我以為我走的是正確的道路,但現在我不太確定。

如果有人可以提供幫助,我們將不勝感激。

由於elasticsearch在本地機器上可用,因此測試用例運行良好。 但是在CircleCI上,您需要明確指定需要彈性搜索。 因此,您需要在circle.yml中的服務下添加“elasticsearch”。

在circle.yml中

machine:
  services:
    - elasticsearch

checkout https://circleci.com/docs/configuration#services以獲取更多信息。

注意默認情況下使用的elasticsearch版本(設置服務時:elasticsearch)為0.92.0(2歲)

但是,您可以安裝elasticsearch的自定義版本 並且不要忘記從“服務”字段中刪除elasticsearch。

但是彈性搜索可能需要一些時間才能使用,因此您需要編寫一個腳本來重試連接。

下面是使用nodejs sdk的示例:此代碼位於我的testsuite的所有鈎子中:

before(function(done){
  var count = 1;
  function _setup (c) {
    return client.ping({pingTimeout: 4000})
     .then(function () {
       done();
      })
     .catch(function (err) {
       console.log(err);
       console.log('retry ', c);
       return setTimeout(function () {
         _setup(count++);
       }, 4000);
    });
   }
   _setup(count);
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM