Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-el committed Nov 9, 2023
1 parent 01fc1aa commit 780bcbb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 6 additions & 6 deletions libraries/browser-tracker-core/src/tracker/out_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SharedState } from '../state';
import { localStorageAccessible } from '../detectors';
import { LOG, Payload } from '@snowplow/tracker-core';
import { PAYLOAD_DATA_SCHEMA } from './schemata';
import { EventBatch, RequestFailure } from './types';
import { EventBatch, PostBatch, RequestFailure } from './types';

export interface OutQueue {
enqueueRequest: (request: Payload, url: string) => void;
Expand Down Expand Up @@ -228,11 +228,11 @@ export function OutQueueManager(
function sendPostRequestWithoutQueueing(body: PostEvent, configCollectorUrl: string) {
const xhr = initializeXMLHttpRequest(configCollectorUrl, true, false);
const batch = attachStmToEvent([body.evt]);
currentBatch = batch;
currentBatch = batch as PostBatch;

// The timeout and onreadystatechange events are not set for oversized requests
// so we must set them here to listen for the response
setXhrCallbacks(xhr, 0);
setXhrCallbacks(xhr, 0, false);

xhr.send(encloseInPayloadDataEnvelope(batch));
}
Expand All @@ -246,19 +246,19 @@ export function OutQueueManager(
}
};

function setXhrCallbacks(xhr: XMLHttpRequest, numberToSend: number) {
function setXhrCallbacks(xhr: XMLHttpRequest, numberToSend: number, useQueue: boolean = true) {
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
clearTimeout(xhrTimeout);
if (xhr.status >= 200 && xhr.status < 300) {
onRequestSuccess?.(currentBatch.slice());
removeEventsFromQueue(numberToSend);
useQueue && removeEventsFromQueue(numberToSend);
executeQueue();
} else {
if (!shouldRetryForStatusCode(xhr.status)) {
LOG.error(`Status ${xhr.status}, will not retry.`);
tryOnRequestFailure(xhr.status, xhr.statusText);
removeEventsFromQueue(numberToSend);
useQueue && removeEventsFromQueue(numberToSend);
}
executingQueue = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,12 @@ describe('Snowplow Micro integration', () => {
beforeAll(async () => {
testIdentifier = await pageSetup();
await loadUrlAndWait('/integration.html?eventMethod=get');
await browser.pause(5000); // Time for requests to get written
await $('#bottomRight').click();
await browser.pause(5000); // Time for requests to get written
await loadUrlAndWait('/integration.html?eventMethod=post');
await browser.pause(5000); // Time for requests to get written
await $('#bottomRight').click();
await browser.pause(6000); // Time for requests to get written
await loadUrlAndWait('/integration.html?eventMethod=beacon');
await browser.pause(5000); // Time for requests to get written
await $('#bottomRight').click();
await browser.pause(6000); // Time for requests to get written
log = await browser.call(async () => await fetchResults());
Expand Down

0 comments on commit 780bcbb

Please sign in to comment.