Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenthebuilder committed Apr 13, 2024
1 parent 1812f18 commit b360a7b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { diffLines } from "diff";
import { KvRpcTest } from "./tests/kv_rpc";
import { KvSubscribeErrorTest, KvSubscribeMultipleTest, KvSubscribeTest } from "./tests/kv_subscribe";
import { NetworkDisconnectTest, BufferRequestTest, SubscriptionDisconnectTest, SubscriptionReconnectTest } from "./tests/test_network";
import { NetworkDisconnectTest, BufferRequestTest, SubscriptionDisconnectTest, SubscriptionReconnectTest, OneClientDisconnectTest } from "./tests/test_network";
import { buildImage, cleanup, setupNetwork, type ContainerHandle, applyAction, setupContainer, type ClientContainer } from "./src/docker";
import { RepeatEchoPrefixTest, RepeatEchoTest } from "./tests/repeat_stream";
import { UploadSendTest } from "./tests/send_upload";
Expand Down Expand Up @@ -160,6 +160,7 @@ await runSuite({
"network buffer requests": BufferRequestTest,
"network subscription disconnect": SubscriptionDisconnectTest,
"network subscription reconnect": SubscriptionReconnectTest,
"network multi clients one disconnect": OneClientDisconnectTest
})

await cleanup();
2 changes: 1 addition & 1 deletion tests/kv_subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ export const KvSubscribeMultipleTest: Test = {
{ id: "b", status: "ok", payload: 41 },
],
},
};
};
35 changes: 35 additions & 0 deletions tests/test_network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,38 @@ export const SubscriptionReconnectTest: Test = {
],
},
};


export const OneClientDisconnectTest: Test = {
client1: {
actions: [
{ type: "invoke", id: "1", proc: "kv.set", payload: { k: "foo", v: 42 } },
{ type: "invoke", id: "2", proc: "kv.watch", payload: { k: "foo" } },
{ type: "wait", ms: 500 },
{ type: "disconnect_network" },
{ type: "invoke", id: "3", proc: "kv.set", payload: { k: "foo", v: 1 } },
{ type: "wait", ms: 500 },
{ type: "connect_network" },
],
expectedOutput: [
{ id: "1", status: "ok", payload: 42 },
{ id: "2", status: "ok", payload: 42 },
{ id: "2", status: "ok", payload: 46 },
{ id: "2", status: "ok", payload: 1 },
{ id: "3", status: "ok", payload: 1 },
],
},
client2: {
actions: [
{ type: "wait", ms: 800 },
{ type: "invoke", id: "5", proc: "kv.watch", payload: { k: "foo" } },
{ type: "invoke", id: "6", proc: "kv.set", payload: { k: "foo", v: 46 } },
],
expectedOutput: [
{ id: "5", status: "ok", payload: 42 },
{ id: "5", status: "ok", payload: 46 },
{ id: "6", status: "ok", payload: 46 },
{ id: "5", status: "ok", payload: 1 },
],
},
};

0 comments on commit b360a7b

Please sign in to comment.