Skip to content

Commit

Permalink
Add tests for the noDelay option
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrove committed Aug 23, 2023
1 parent 3a343d2 commit 6d90249
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion packages/memcache-client/src/test/spec/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Path from "path";
import { text1, text2, poem1, poem2, poem3, poem4, poem5 } from "../data/text";
import NullLoger from "../../lib/null-logger";
import memcached, { MemcachedServer } from "memcached-njs";
import { AddressInfo } from "net";
import { AddressInfo, Socket } from "net";

describe("memcache client", function () {
process.on("unhandledRejection", (e) => {
Expand Down Expand Up @@ -279,6 +279,40 @@ describe("memcache client", function () {
});
});

it("should not enable TCP_NODELAY by default", async () => {
await startSingleServer();

const _setNoDelay = Socket.prototype.setNoDelay;
const mockNoDelay = jest.fn();

try {
Socket.prototype.setNoDelay = mockNoDelay;
const x = new MemcacheClient({ server: server });
await x.set("foo", "bar");
} finally {
Socket.prototype.setNoDelay = _setNoDelay;
}

expect(mockNoDelay).not.toHaveBeenCalled();
});

it("should enable TCP_NODELAY when options.noDelay is true", async () => {
await startSingleServer();

const _setNoDelay = Socket.prototype.setNoDelay;
const mockNoDelay = jest.fn();

try {
Socket.prototype.setNoDelay = mockNoDelay;
const x = new MemcacheClient({ server: server, noDelay: true });
await x.set("foo", "bar");
} finally {
Socket.prototype.setNoDelay = _setNoDelay;
}

expect(mockNoDelay).toHaveBeenCalled();
});

const testMulti = (maxConnections: number = 1, done: () => void) => {
const key1 = "text1维基百科";
const key2 = "blah";
Expand Down

0 comments on commit 6d90249

Please sign in to comment.