Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("GenericContainer resources quota", { timeout: 180_000 }, () => {
if (!process.env["CI_ROOTLESS"]) {
it("should set resources quota", async () => {
await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
.withResourcesQuota({ memory: 0.5, cpu: 1 })
.withResourcesQuota({ cpu: 1, memory: 0.5 })
.start();

const dockerContainer = await client.container.getById(container.getId());
Expand Down Expand Up @@ -44,6 +44,20 @@ describe("GenericContainer resources quota", { timeout: 180_000 }, () => {
expect(containerInfo.HostConfig.NanoCpus).toEqual(0);
});

if (!process.env["CI_ROOTLESS"]) {
it("should round values to match target int64 type", async () => {
await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
.withResourcesQuota({ cpu: 0.3, memory: 0.2 })
.start();

const dockerContainer = await client.container.getById(container.getId());
const containerInfo = await dockerContainer.inspect();

expect(containerInfo.HostConfig.Memory).toEqual(214748365);
expect(containerInfo.HostConfig.NanoCpus).toEqual(300000000);
});
}

if (!process.env["CI_ROOTLESS"]) {
it("should set resources quota cpu only, memory should be 0", async () => {
await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ export class GenericContainer implements TestContainer {
}

public withResourcesQuota({ memory, cpu }: ResourcesQuota): this {
this.hostConfig.Memory = memory !== undefined ? memory * 1024 ** 3 : undefined;
this.hostConfig.NanoCpus = cpu !== undefined ? cpu * 10 ** 9 : undefined;
this.hostConfig.Memory = memory !== undefined ? Math.ceil(memory * 1024 ** 3) : undefined;
this.hostConfig.NanoCpus = cpu !== undefined ? Math.ceil(cpu * 10 ** 9) : undefined;
return this;
}

Expand Down
Loading