Skip to content

Commit

Permalink
[Main][Task]25693679: Extract common sendPost implementation for onli…
Browse files Browse the repository at this point in the history
…ne and offline sender (#2285)

* copy1

* add send common interface

* update

* update

* update

* mark interface as internal

* update

* update

* update

* update

* update

* udpate
  • Loading branch information
Karlie-777 authored Mar 4, 2024
1 parent cd3b694 commit a20e689
Show file tree
Hide file tree
Showing 15 changed files with 1,195 additions and 936 deletions.
8 changes: 4 additions & 4 deletions AISKU/Tests/Unit/src/AISKUSize.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { Snippet } from "../../../src/Snippet";
import { utlRemoveSessionStorage } from "@microsoft/applicationinsights-common";

export class AISKUSizeCheck extends AITestClass {
private readonly MAX_RAW_SIZE = 136;
private readonly MAX_BUNDLE_SIZE = 136;
private readonly MAX_RAW_DEFLATE_SIZE = 55;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 55;
private readonly MAX_RAW_SIZE = 138;
private readonly MAX_BUNDLE_SIZE = 138;
private readonly MAX_RAW_DEFLATE_SIZE = 56;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 56;
private readonly rawFilePath = "../dist/es5/applicationinsights-web.min.js";
// Automatically updated by version scripts
private readonly currentVer = "3.1.0";
Expand Down
8 changes: 4 additions & 4 deletions AISKULight/Tests/Unit/src/AISKULightSize.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { AITestClass, Assert } from "@microsoft/ai-test-framework";
import * as pako from "pako";

export class AISKULightSizeCheck extends AITestClass {
private readonly MAX_RAW_SIZE = 82;
private readonly MAX_BUNDLE_SIZE = 82;
private readonly MAX_RAW_DEFLATE_SIZE = 34;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 34;
private readonly MAX_RAW_SIZE = 85;
private readonly MAX_BUNDLE_SIZE = 85;
private readonly MAX_RAW_DEFLATE_SIZE = 35;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 35;
private readonly rawFilePath = "../dist/es5/applicationinsights-web-basic.min.js";
private readonly currentVer = "3.1.0";
private readonly prodFilePath = `../browser/es5/aib.${this.currentVer[0]}.min.js`;
Expand Down
561 changes: 150 additions & 411 deletions channels/applicationinsights-channel-js/src/Sender.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,17 @@ export class OfflineBatchHandlerTests extends AITestClass {
sender1Payload.push(payload);
oncomplete(400, {});
}
// 200 should be called first, in some case, re-try will be added back (sender2) and event2 will be returned again
// This is to guarantee the test gets events in order
let sender2Payload: any[] = []
let sender2 = (payload: IPayloadData, oncomplete: OnCompleteCallback, sync?: boolean) => {
sender2Payload.push(payload);
oncomplete(500, {});
oncomplete(200, {});
}
let sender3Payload: any[] = []
let sender3 = (payload: IPayloadData, oncomplete: OnCompleteCallback, sync?: boolean) => {
sender3Payload.push(payload);
oncomplete(200, {});
oncomplete(500, {});
}

let res1: any[] = [];
Expand All @@ -565,6 +567,7 @@ export class OfflineBatchHandlerTests extends AITestClass {
this.ctx.sendBatch1Res = res1;
this.ctx.sendBatch1Pd = sender1Payload;
});

let res2: any[] = [];
let cb2 = (res) => {
res2.push(res);
Expand All @@ -575,6 +578,7 @@ export class OfflineBatchHandlerTests extends AITestClass {
this.ctx.sendBatch2Res = res2;
this.ctx.sendBatch2Pd = sender2Payload;
});

let res3: any[] = [];
let cb3 = (res) => {
res3.push(res);
Expand All @@ -585,6 +589,8 @@ export class OfflineBatchHandlerTests extends AITestClass {
this.ctx.sendBatch3Pd = sender3Payload;
});



let cb4 = (res) => {
this.ctx.hasBatch1Called = true;
this.ctx.hasBatch1 = res && res.length >= 1;
Expand Down Expand Up @@ -631,7 +637,7 @@ export class OfflineBatchHandlerTests extends AITestClass {
if (sendBatch) {
Assert.equal(res.length, 1, "response 2 should be called once");
let res1 = res[0];
Assert.equal(res1.state, eBatchSendStatus.Retry, "response 2 state should be retry");
Assert.equal(res1.state, eBatchSendStatus.Complete, "response 2 state should be retry");
Assert.ok(res1.data, "response 2 should have data");
Assert.equal(res1.data.criticalCnt, 2 ,"response 2 should have expected data");

Expand All @@ -650,7 +656,7 @@ export class OfflineBatchHandlerTests extends AITestClass {
if (sendBatch) {
Assert.equal(res.length, 1, "response 3 should be called once");
let res1 = res[0];
Assert.equal(res1.state, eBatchSendStatus.Complete, "response 3 state should be complete");
Assert.equal(res1.state, eBatchSendStatus.Retry, "response 3 state should be complete");
Assert.ok(res1.data, "response 3 should have data");
Assert.equal(res1.data.criticalCnt, 3 ,"response 3 should have expected data");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { ChannelTests } from "./channel.tests";
import { Offlinetimer } from "./offlinetimer.tests";

export function runTests() {
// new OfflineIndexedDBTests().registerTests();
// new OfflineWebProviderTests().registerTests();
// new OfflineDbProviderTests().registerTests();
// new OfflineInMemoryBatchTests().registerTests();
// new OfflineBatchHandlerTests().registerTests();
new OfflineIndexedDBTests().registerTests();
new OfflineWebProviderTests().registerTests();
new OfflineDbProviderTests().registerTests();
new OfflineInMemoryBatchTests().registerTests();
new OfflineBatchHandlerTests().registerTests();
new ChannelTests().registerTests();
// new Offlinetimer().registerTests();
new Offlinetimer().registerTests();
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export class Offlinetimer extends AITestClass {
let sendPost = (payload: IPayloadData, oncomplete: OnCompleteCallback, sync?: boolean) => {
// first call, return complete, data null;
called ++;
console.log("test")
oncomplete(200, {});
return;

Expand Down
Loading

0 comments on commit a20e689

Please sign in to comment.