[Search] Don't block UI between requests

Timeout subsequent calls to keepIndexing at the end of a
indexRequest, so that UI operations are not blocked.
This commit is contained in:
Pete Richards
2015-10-21 07:39:59 -07:00
parent 9a63e99710
commit 833f57e284
2 changed files with 35 additions and 19 deletions

View File

@@ -143,17 +143,38 @@ define([
});
describe('keepIndexing', function () {
it('kicks off an index request when not at maximum', function () {
spyOn(provider, 'beginIndexRequest');
provider.pendingRequests = 0;
it('calls beginIndexRequest until at maximum', function () {
spyOn(provider, 'beginIndexRequest').andCallThrough();
provider.pendingRequests = 9;
provider.idsToIndex = ['a', 'b', 'c'];
provider.MAX_CONCURRENT_REQUESTS = 10;
provider.keepIndexing();
expect(provider.beginIndexRequest).toHaveBeenCalled();
expect(provider.beginIndexRequest.calls.length).toBe(1);
});
it('calls beginIndexRequest for all ids to index', function () {
spyOn(provider, 'beginIndexRequest').andCallThrough();
provider.pendingRequests = 0;
provider.idsToIndex = ['a', 'b', 'c'];
provider.MAX_CONCURRENT_REQUESTS = 10;
provider.keepIndexing();
expect(provider.beginIndexRequest).toHaveBeenCalled();
expect(provider.beginIndexRequest.calls.length).toBe(3);
});
it('does not index when at capacity', function () {
spyOn(provider, 'beginIndexRequest');
provider.pendingRequests = 10;
provider.idsToIndex.push('a');
provider.MAX_CONCURRENT_REQUESTS = 10;
provider.keepIndexing();
expect(provider.beginIndexRequest).not.toHaveBeenCalled();
});
it('does not index when no ids to index', function () {
spyOn(provider, 'beginIndexRequest');
provider.pendingRequests = 0;
provider.MAX_CONCURRENT_REQUESTS = 10;
provider.keepIndexing();
expect(provider.beginIndexRequest).not.toHaveBeenCalled();
@@ -222,12 +243,6 @@ define([
});
});
it('does not error if no objects queued', function () {
provider.idsToIndex = [];
expect(function () {
provider.beginIndexRequest();
}).not.toThrow();
});
});