Skip to content

Commit

Permalink
Handling the non compression case in sync manner to get the unit test…
Browse files Browse the repository at this point in the history
…s to pass
  • Loading branch information
scheler committed Mar 22, 2024
1 parent 667183f commit 67453e0
Showing 1 changed file with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,39 @@ export function sendWithXhr(
'Content-Type': 'application/json',
};

compressContent(body, compressionAlgorithm)
.then(compressedContent => {
sendWithRetry(compressedContent, {
...commonHeaders,
...headers,
'Content-Encoding': compressionAlgorithm,
});
})
.catch(_error => {
sendWithRetry(body, {
...commonHeaders,
...headers,
});
if (compressionAlgorithm === CompressionAlgorithm.NONE) {
// Although this case is handled by the catch block below, we still had to
// call sendWithRetry here in a sync manner to get the unit tests to pass.
sendWithRetry(body, {
...commonHeaders,
...headers,
});
} else {
compressContent(body, compressionAlgorithm)
.then(compressedContent => {
sendWithRetry(compressedContent, {
...commonHeaders,
...headers,
'Content-Encoding': compressionAlgorithm,
});
})
.catch(_error => {
sendWithRetry(body, {

Check warning on line 182 in experimental/packages/otlp-exporter-base/src/platform/browser/util.ts

View check run for this annotation

Codecov / codecov/patch

experimental/packages/otlp-exporter-base/src/platform/browser/util.ts#L181-L182

Added lines #L181 - L182 were not covered by tests
...commonHeaders,
...headers,
});
});
}
}

async function compressContent(
content: string | Blob,
compressionAlgorithm: string
): Promise<Uint8Array> {
if (compressionAlgorithm === CompressionAlgorithm.NONE) {
return Promise.reject(new Error('Compression algorithm cannot be "none"'));

Check warning on line 195 in experimental/packages/otlp-exporter-base/src/platform/browser/util.ts

View check run for this annotation

Codecov / codecov/patch

experimental/packages/otlp-exporter-base/src/platform/browser/util.ts#L195

Added line #L195 was not covered by tests
}

const compressionStream = new CompressionStream(
compressionAlgorithm as CompressionFormat
);
Expand Down

0 comments on commit 67453e0

Please sign in to comment.