Skip to content

Commit fedab36

Browse files
Resource quota returns 400 when contains decimals
1 parent 0c3d4e4 commit fedab36

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/testcontainers/src/generic-container/generic-container-resources-quota.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ describe("GenericContainer resources quota", { timeout: 180_000 }, () => {
4444
expect(containerInfo.HostConfig.NanoCpus).toEqual(0);
4545
});
4646

47+
it("should round values to match target int64 type", async () => {
48+
await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
49+
.withResourcesQuota({ memory: 0.2, cpu: 0.3 })
50+
.start();
51+
52+
const dockerContainer = await client.container.getById(container.getId());
53+
const containerInfo = await dockerContainer.inspect();
54+
55+
expect(containerInfo.HostConfig.Memory).toEqual(214748365);
56+
expect(containerInfo.HostConfig.NanoCpus).toEqual(300000000);
57+
});
58+
4759
if (!process.env["CI_ROOTLESS"]) {
4860
it("should set resources quota cpu only, memory should be 0", async () => {
4961
await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")

packages/testcontainers/src/generic-container/generic-container.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ export class GenericContainer implements TestContainer {
484484
}
485485

486486
public withResourcesQuota({ memory, cpu }: ResourcesQuota): this {
487-
this.hostConfig.Memory = memory !== undefined ? memory * 1024 ** 3 : undefined;
488-
this.hostConfig.NanoCpus = cpu !== undefined ? cpu * 10 ** 9 : undefined;
487+
this.hostConfig.Memory = memory !== undefined ? Math.ceil(memory * 1024 ** 3) : undefined;
488+
this.hostConfig.NanoCpus = cpu !== undefined ? Math.ceil(cpu * 10 ** 9) : undefined;
489489
return this;
490490
}
491491

0 commit comments

Comments
 (0)