gpt4 book ai didi

node.js - 在每个文本(Mocha,Elastic)之前清理索引

转载 作者:行者123 更新时间:2023-12-03 01:07:25 25 4
gpt4 key购买 nike

在每次测试之前,我们如何清除索引? (目前我的测试未通过,并且超时)

我努力了

  • DeleteBy(我已经尝试过术语和q)
  • http删除
  • 删除索引

  • 我有以下代码:
    var assert = require("assert"),
    elasticsearch = require('elasticsearch'),
    request = require('request'),
    q = require('q'),
    client;

    client = new elasticsearch.Client();

    describe('people', function(){

    beforeEach(function(done){

    //is this correct?
    //looks like poeple get deleted.
    client.deleteByQuery({
    index: 'people',
    q: '*'
    }, function (error, response) {
    done();
    });

    //I have also tried the following:

    //this way returns an accept code.

    // var deleteOptions = {
    // method: 'DELETE',
    // uri: 'http://localhost:9200/people/person'
    // };
    //
    // webApi(deleteOptions).then(function(data){
    // //{"acknowledged":true}
    // console.log(data.body);
    // done();
    // });


    //the following throws an exception

    //delete index

    // client.indices.delete('people').then(function(del){
    // console.log(del);
    // client.indices.create('people').then(function(ct){
    // console.log(ct);
    // done();
    // });
    // });






    });

    describe('add a entry into the index', function(){
    it('should add Dave as a person to the database', function(done){

    //THIS TEST WILL FAIL
    //Error: timeout of 2000ms exceeded

    //I have tried adding a timeout.

    assert.equal(1,1);
    });
    });
    });

    var webApi = function(options){
    var deferred = q.defer();
    var handle = function (error, response, body) {
    //console.log(body);
    if(error) {
    deferred.reject(error);
    }
    else {
    deferred.resolve({response:response, body:body});
    }
    };
    request(options, handle);
    return deferred.promise; //NOTE: we now return a promise
    };

    最佳答案

    您标记为THIS TEST WILL FAIL的测试因超时而失败,因为您从未在其中调用done()。您已经使用参数声明了传递给it的匿名函数,该函数告诉Mocha您的测试是异步的(即使其中的代码当前不是异步的),因此Mocha等待done()的调用。您可以调用它,也可以从函数中删除参数。

    关于node.js - 在每个文本(Mocha,Elastic)之前清理索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25565125/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com