Merge branch 'master' into master
This commit is contained in:
commit
79c1b4ccf3
|
@ -630,9 +630,9 @@ Client.prototype.search = function search (base,
|
|||
callback: callback,
|
||||
controls: controls,
|
||||
pageSize: size,
|
||||
pagePause: pageOpts.pagePause
|
||||
pagePause: pageOpts.pagePause,
|
||||
sendRequest: sendRequest
|
||||
})
|
||||
pager.on('search', sendRequest)
|
||||
pager.begin()
|
||||
} else {
|
||||
sendRequest(controls, new CorkedEmitter(), callback)
|
||||
|
|
|
@ -10,6 +10,8 @@ const assert = require('assert-plus')
|
|||
// var Protocol = require('../protocol')
|
||||
const PagedControl = require('../controls/paged_results_control.js')
|
||||
|
||||
const CorkedEmitter = require('../corked_emitter.js')
|
||||
|
||||
/// --- API
|
||||
|
||||
/**
|
||||
|
@ -29,19 +31,20 @@ const PagedControl = require('../controls/paged_results_control.js')
|
|||
* will be emitted (and 'end' will not be). By listening to
|
||||
* 'pageError', a successful search that lacks paging will be
|
||||
* able to emit 'end'.
|
||||
* 3. search - Emitted as an internal event to trigger another client search.
|
||||
*/
|
||||
function SearchPager (opts) {
|
||||
assert.object(opts)
|
||||
assert.func(opts.callback)
|
||||
assert.number(opts.pageSize)
|
||||
assert.func(opts.sendRequest)
|
||||
|
||||
EventEmitter.call(this, {})
|
||||
CorkedEmitter.call(this, {})
|
||||
|
||||
this.callback = opts.callback
|
||||
this.controls = opts.controls
|
||||
this.pageSize = opts.pageSize
|
||||
this.pagePause = opts.pagePause
|
||||
this.sendRequest = opts.sendRequest
|
||||
|
||||
this.controls.forEach(function (control) {
|
||||
if (control.type === PagedControl.OID) {
|
||||
|
@ -61,7 +64,7 @@ function SearchPager (opts) {
|
|||
emitter.on('error', this._onError.bind(this))
|
||||
this.childEmitter = emitter
|
||||
}
|
||||
util.inherits(SearchPager, EventEmitter)
|
||||
util.inherits(SearchPager, CorkedEmitter)
|
||||
module.exports = SearchPager
|
||||
|
||||
/**
|
||||
|
@ -144,8 +147,7 @@ SearchPager.prototype._nextPage = function _nextPage (cookie) {
|
|||
}
|
||||
}))
|
||||
|
||||
this.emit('search', controls, this.childEmitter,
|
||||
this._sendCallback.bind(this))
|
||||
this.sendRequest(controls, this.childEmitter, this._sendCallback.bind(this))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -911,6 +911,25 @@ tap.test('search paged', { timeout: 10000 }, function (t) {
|
|||
})
|
||||
})
|
||||
|
||||
tap.test('paged - search with delayed event listener binding', function (t) {
|
||||
t.context.client.search('cn=paged', { filter: '(objectclass=*)', paged: true }, function (err, res) {
|
||||
t.error(err)
|
||||
setTimeout(() => {
|
||||
let gotEntry = 0
|
||||
res.on('searchEntry', function () {
|
||||
gotEntry++
|
||||
})
|
||||
res.on('error', function (err) {
|
||||
t.fail(err)
|
||||
})
|
||||
res.on('end', function () {
|
||||
t.equal(gotEntry, 1000)
|
||||
t.end()
|
||||
})
|
||||
}, 100)
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue