Skip to content

Commit

Permalink
fix(core-cli): check total memory only (#4503)
Browse files Browse the repository at this point in the history
* Check total memory only

* Remove unused import

* Fix tests
  • Loading branch information
rainydio authored Sep 21, 2021
1 parent 26d49d8 commit 3142b40
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
20 changes: 1 addition & 19 deletions __tests__/unit/core-cli/actions/daemonize-process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ describe("DaemonizeProcess", () => {
const has = jest.spyOn(processManager, "has").mockReturnValue(true);
const isUnknown = jest.spyOn(processManager, "isUnknown").mockReturnValue(false);
const isOnline = jest.spyOn(processManager, "isOnline").mockReturnValue(false);
const freemem = jest.spyOn(os, "freemem").mockReturnValue(99999999999);
const totalmem = jest.spyOn(os, "totalmem").mockReturnValue(99999999999);
const start = jest.spyOn(processManager, "start").mockImplementation(undefined);

Expand All @@ -107,7 +106,6 @@ describe("DaemonizeProcess", () => {
expect(has).toHaveBeenCalledWith("ark-core");
expect(isUnknown).toHaveBeenCalledWith("ark-core");
expect(isOnline).toHaveBeenCalledWith("ark-core");
expect(freemem).toHaveBeenCalled();
expect(totalmem).toHaveBeenCalled();
expect(start).toHaveBeenCalledWith(
{
Expand All @@ -123,7 +121,6 @@ describe("DaemonizeProcess", () => {
has.mockClear();
isUnknown.mockClear();
isOnline.mockClear();
freemem.mockClear();
totalmem.mockClear();
start.mockClear();
});
Expand All @@ -132,7 +129,6 @@ describe("DaemonizeProcess", () => {
const has = jest.spyOn(processManager, "has").mockReturnValue(true);
const isUnknown = jest.spyOn(processManager, "isUnknown").mockReturnValue(false);
const isOnline = jest.spyOn(processManager, "isOnline").mockReturnValue(false);
const freemem = jest.spyOn(os, "freemem").mockReturnValue(99999999999);
const totalmem = jest.spyOn(os, "totalmem").mockReturnValue(99999999999);
const start = jest.spyOn(processManager, "start").mockImplementation(undefined);

Expand All @@ -148,7 +144,6 @@ describe("DaemonizeProcess", () => {
expect(has).toHaveBeenCalledWith("ark-core");
expect(isUnknown).toHaveBeenCalledWith("ark-core");
expect(isOnline).toHaveBeenCalledWith("ark-core");
expect(freemem).toHaveBeenCalled();
expect(totalmem).toHaveBeenCalled();
expect(start).toHaveBeenCalledWith(
{
Expand All @@ -164,7 +159,6 @@ describe("DaemonizeProcess", () => {
has.mockClear();
isUnknown.mockClear();
isOnline.mockClear();
freemem.mockClear();
totalmem.mockClear();
start.mockClear();
});
Expand All @@ -173,7 +167,6 @@ describe("DaemonizeProcess", () => {
const has = jest.spyOn(processManager, "has").mockReturnValue(true);
const isUnknown = jest.spyOn(processManager, "isUnknown").mockReturnValue(false);
const isOnline = jest.spyOn(processManager, "isOnline").mockReturnValue(false);
const freemem = jest.spyOn(os, "freemem").mockReturnValue(99999999999);
const totalmem = jest.spyOn(os, "totalmem").mockReturnValue(99999999999);
const start = jest.spyOn(processManager, "start").mockImplementation(undefined);

Expand All @@ -189,7 +182,6 @@ describe("DaemonizeProcess", () => {
expect(has).toHaveBeenCalledWith("ark-core");
expect(isUnknown).toHaveBeenCalledWith("ark-core");
expect(isOnline).toHaveBeenCalledWith("ark-core");
expect(freemem).toHaveBeenCalled();
expect(totalmem).toHaveBeenCalled();
expect(start).toHaveBeenCalledWith(
{
Expand All @@ -205,7 +197,6 @@ describe("DaemonizeProcess", () => {
has.mockClear();
isUnknown.mockClear();
isOnline.mockClear();
freemem.mockClear();
totalmem.mockClear();
start.mockClear();
});
Expand All @@ -214,8 +205,7 @@ describe("DaemonizeProcess", () => {
const has = jest.spyOn(processManager, "has").mockReturnValue(true);
const isUnknown = jest.spyOn(processManager, "isUnknown").mockReturnValue(false);
const isOnline = jest.spyOn(processManager, "isOnline").mockReturnValue(false);
const freemem = jest.spyOn(os, "freemem").mockReturnValue(1);
const totalmem = jest.spyOn(os, "totalmem").mockReturnValue(1);
const totalmem = jest.spyOn(os, "totalmem").mockReturnValue(2 * 1024 ** 3 - 1);
const start = jest.spyOn(processManager, "start").mockImplementation(undefined);

action.execute(
Expand All @@ -230,7 +220,6 @@ describe("DaemonizeProcess", () => {
expect(has).toHaveBeenCalledWith("ark-core");
expect(isUnknown).toHaveBeenCalledWith("ark-core");
expect(isOnline).toHaveBeenCalledWith("ark-core");
expect(freemem).toHaveBeenCalled();
expect(totalmem).toHaveBeenCalled();
expect(start).toHaveBeenCalledWith(
{
Expand All @@ -251,7 +240,6 @@ describe("DaemonizeProcess", () => {
has.mockClear();
isUnknown.mockClear();
isOnline.mockClear();
freemem.mockClear();
totalmem.mockClear();
start.mockClear();
});
Expand All @@ -260,7 +248,6 @@ describe("DaemonizeProcess", () => {
const has = jest.spyOn(processManager, "has").mockReturnValue(true);
const isUnknown = jest.spyOn(processManager, "isUnknown").mockReturnValue(false);
const isOnline = jest.spyOn(processManager, "isOnline").mockReturnValue(false);
const freemem = jest.spyOn(os, "freemem").mockReturnValue(99999999999);
const totalmem = jest.spyOn(os, "totalmem").mockReturnValue(99999999999);
const start = jest.spyOn(processManager, "start").mockImplementation(() => {
throw new Error("unexpected error");
Expand All @@ -280,7 +267,6 @@ describe("DaemonizeProcess", () => {
expect(has).toHaveBeenCalledWith("ark-core");
expect(isUnknown).toHaveBeenCalledWith("ark-core");
expect(isOnline).toHaveBeenCalledWith("ark-core");
expect(freemem).toHaveBeenCalled();
expect(totalmem).toHaveBeenCalled();
expect(start).toHaveBeenCalledWith(
{
Expand All @@ -296,7 +282,6 @@ describe("DaemonizeProcess", () => {
has.mockClear();
isUnknown.mockClear();
isOnline.mockClear();
freemem.mockClear();
totalmem.mockClear();
start.mockClear();
});
Expand All @@ -305,7 +290,6 @@ describe("DaemonizeProcess", () => {
const has = jest.spyOn(processManager, "has").mockReturnValue(true);
const isUnknown = jest.spyOn(processManager, "isUnknown").mockReturnValue(false);
const isOnline = jest.spyOn(processManager, "isOnline").mockReturnValue(false);
const freemem = jest.spyOn(os, "freemem").mockReturnValue(99999999999);
const totalmem = jest.spyOn(os, "totalmem").mockReturnValue(99999999999);
const start = jest.spyOn(processManager, "start").mockImplementation(() => {
const error: Error = new Error("hello world");
Expand All @@ -329,7 +313,6 @@ describe("DaemonizeProcess", () => {
expect(has).toHaveBeenCalledWith("ark-core");
expect(isUnknown).toHaveBeenCalledWith("ark-core");
expect(isOnline).toHaveBeenCalledWith("ark-core");
expect(freemem).toHaveBeenCalled();
expect(totalmem).toHaveBeenCalled();
expect(start).toHaveBeenCalledWith(
{
Expand All @@ -345,7 +328,6 @@ describe("DaemonizeProcess", () => {
has.mockClear();
isUnknown.mockClear();
isOnline.mockClear();
freemem.mockClear();
totalmem.mockClear();
start.mockClear();
});
Expand Down
6 changes: 2 additions & 4 deletions packages/core-cli/src/actions/daemonize-process.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { freemem, totalmem } from "os";
import { totalmem } from "os";

import { Application } from "../application";
import { Spinner } from "../components";
Expand Down Expand Up @@ -59,9 +59,7 @@ export class DaemonizeProcess {

flagsProcess.name = processName;

const totalMemGb: number = totalmem() / Math.pow(1024, 3);
const freeMemGb: number = freemem() / Math.pow(1024, 3);
const potato: boolean = totalMemGb < 2 || freeMemGb < 1.5;
const potato: boolean = totalmem() < 2 * 1024 ** 3;

this.processManager.start(
{
Expand Down

0 comments on commit 3142b40

Please sign in to comment.