Skip to content

Commit bae520f

Browse files
committed
format source
1 parent f866605 commit bae520f

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

src/util/token-bucket.test.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,51 @@ import { describe, expect, it } from "bun:test";
22
import { createTokenBucket } from "./token-bucket";
33

44
describe("Token Bucket", () => {
5-
it("allows bursts up to capacity and blocks after", () => {
6-
const capacity = 5;
7-
const windowMs = 100;
8-
const bucket = createTokenBucket(capacity, windowMs);
5+
it("allows bursts up to capacity and blocks after", () => {
6+
const capacity = 5;
7+
const windowMs = 100;
8+
const bucket = createTokenBucket(capacity, windowMs);
99

10-
for (let i = 0; i < capacity; i++) {
11-
expect(bucket.allow()).toBe(true);
12-
}
10+
for (let i = 0; i < capacity; i++) {
11+
expect(bucket.allow()).toBe(true);
12+
}
1313

14-
expect(bucket.allow()).toBe(false);
15-
});
14+
expect(bucket.allow()).toBe(false);
15+
});
1616

17-
it("refills tokens over time", async () => {
18-
const capacity = 5;
19-
const windowMs = 10;
20-
const bucket = createTokenBucket(capacity, windowMs);
17+
it("refills tokens over time", async () => {
18+
const capacity = 5;
19+
const windowMs = 10;
20+
const bucket = createTokenBucket(capacity, windowMs);
2121

22-
for (let i = 0; i < capacity; i++) bucket.allow();
22+
for (let i = 0; i < capacity; i++) bucket.allow();
2323

24-
await Bun.sleep(5);
24+
await Bun.sleep(5);
2525

26-
let allowedCount = 0;
27-
for (let i = 0; i < 3; i++) {
28-
if (bucket.allow()) allowedCount++;
29-
}
26+
let allowedCount = 0;
27+
for (let i = 0; i < 3; i++) {
28+
if (bucket.allow()) allowedCount++;
29+
}
3030

31-
expect(allowedCount).toBe(2);
32-
expect(bucket.allow()).toBe(false);
33-
});
31+
expect(allowedCount).toBe(2);
32+
expect(bucket.allow()).toBe(false);
33+
});
3434

35-
it("resets to full capacity after full window", async () => {
36-
const capacity = 5;
37-
const windowMs = 5;
38-
const bucket = createTokenBucket(capacity, windowMs);
35+
it("resets to full capacity after full window", async () => {
36+
const capacity = 5;
37+
const windowMs = 5;
38+
const bucket = createTokenBucket(capacity, windowMs);
3939

40-
for (let i = 0; i < capacity; i++) bucket.allow();
40+
for (let i = 0; i < capacity; i++) bucket.allow();
4141

42-
await Bun.sleep(windowMs);
42+
await Bun.sleep(windowMs);
4343

44-
let allowedCount = 0;
45-
for (let i = 0; i < capacity; i++) {
46-
if (bucket.allow()) allowedCount++;
47-
}
44+
let allowedCount = 0;
45+
for (let i = 0; i < capacity; i++) {
46+
if (bucket.allow()) allowedCount++;
47+
}
4848

49-
expect(allowedCount).toBe(capacity);
50-
expect(bucket.allow()).toBe(false);
51-
});
49+
expect(allowedCount).toBe(capacity);
50+
expect(bucket.allow()).toBe(false);
51+
});
5252
});

0 commit comments

Comments
 (0)