Merge branch 'master' into master

This commit is contained in:
Tony Brix 2021-05-27 14:08:37 -05:00 committed by GitHub
commit 79c1b4ccf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 7 deletions

View File

@ -630,9 +630,9 @@ Client.prototype.search = function search (base,
callback: callback, callback: callback,
controls: controls, controls: controls,
pageSize: size, pageSize: size,
pagePause: pageOpts.pagePause pagePause: pageOpts.pagePause,
sendRequest: sendRequest
}) })
pager.on('search', sendRequest)
pager.begin() pager.begin()
} else { } else {
sendRequest(controls, new CorkedEmitter(), callback) sendRequest(controls, new CorkedEmitter(), callback)

View File

@ -10,6 +10,8 @@ const assert = require('assert-plus')
// var Protocol = require('../protocol') // var Protocol = require('../protocol')
const PagedControl = require('../controls/paged_results_control.js') const PagedControl = require('../controls/paged_results_control.js')
const CorkedEmitter = require('../corked_emitter.js')
/// --- API /// --- API
/** /**
@ -29,19 +31,20 @@ const PagedControl = require('../controls/paged_results_control.js')
* will be emitted (and 'end' will not be). By listening to * will be emitted (and 'end' will not be). By listening to
* 'pageError', a successful search that lacks paging will be * 'pageError', a successful search that lacks paging will be
* able to emit 'end'. * able to emit 'end'.
* 3. search - Emitted as an internal event to trigger another client search.
*/ */
function SearchPager (opts) { function SearchPager (opts) {
assert.object(opts) assert.object(opts)
assert.func(opts.callback) assert.func(opts.callback)
assert.number(opts.pageSize) assert.number(opts.pageSize)
assert.func(opts.sendRequest)
EventEmitter.call(this, {}) CorkedEmitter.call(this, {})
this.callback = opts.callback this.callback = opts.callback
this.controls = opts.controls this.controls = opts.controls
this.pageSize = opts.pageSize this.pageSize = opts.pageSize
this.pagePause = opts.pagePause this.pagePause = opts.pagePause
this.sendRequest = opts.sendRequest
this.controls.forEach(function (control) { this.controls.forEach(function (control) {
if (control.type === PagedControl.OID) { if (control.type === PagedControl.OID) {
@ -61,7 +64,7 @@ function SearchPager (opts) {
emitter.on('error', this._onError.bind(this)) emitter.on('error', this._onError.bind(this))
this.childEmitter = emitter this.childEmitter = emitter
} }
util.inherits(SearchPager, EventEmitter) util.inherits(SearchPager, CorkedEmitter)
module.exports = SearchPager module.exports = SearchPager
/** /**
@ -144,8 +147,7 @@ SearchPager.prototype._nextPage = function _nextPage (cookie) {
} }
})) }))
this.emit('search', controls, this.childEmitter, this.sendRequest(controls, this.childEmitter, this._sendCallback.bind(this))
this._sendCallback.bind(this))
} }
/** /**

View File

@ -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() t.end()
}) })