Skip to content

Commit

Permalink
fix: version is available only when Drive is up
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Oct 18, 2024
1 parent ca0c223 commit bd518c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
28 changes: 14 additions & 14 deletions packages/dashmate/src/status/scopes/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@ export default function getPlatformScopeFactory(
throw e;
}
}
}

try {
const driveVersionResult = await dockerCompose.execCommand(
config,
'drive_abci',
'drive-abci version',
);
try {
const driveVersionResult = await dockerCompose.execCommand(
config,
'drive_abci',
'drive-abci version',
);

info.version = driveVersionResult.out.trim();
} catch (e) {
// Throw an error if it's not a Drive issue
if (!(e instanceof DockerComposeError
&& e.dockerComposeExecutionResult
&& e.dockerComposeExecutionResult.exitCode !== 0)) {
throw e;
}
info.version = driveVersionResult.out.trim();
} catch (e) {
// Throw an error if it's not a Drive issue
if (!(e instanceof DockerComposeError
&& e.dockerComposeExecutionResult
&& e.dockerComposeExecutionResult.exitCode !== 0)) {
throw e;
}
}

Expand Down
25 changes: 18 additions & 7 deletions packages/dashmate/test/unit/status/scopes/platform.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ContainerIsNotPresentError
from '../../../../src/docker/errors/ContainerIsNotPresentError.js';
import DockerComposeError from '../../../../src/docker/errors/DockerComposeError.js';
import providers from '../../../../src/status/providers.js';
import determineStatus from '../../../../src/status/determineStatus.js';
import getConfigMock from '../../../../src/test/mock/getConfigMock.js';
Expand Down Expand Up @@ -73,7 +74,8 @@ describe('getPlatformScopeFactory', () => {
},
});
mockDockerCompose.isServiceRunning.returns(true);
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci status').resolves({ exitCode: 0, out: '' });
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));

const mockStatus = {
Expand Down Expand Up @@ -121,6 +123,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '1.4.1',
},
};

Expand All @@ -147,7 +150,7 @@ describe('getPlatformScopeFactory', () => {
},
});
mockDockerCompose.isServiceRunning.returns(true);
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));

const mockStatus = {
Expand Down Expand Up @@ -195,6 +198,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '1.4.1',
},
};

Expand All @@ -212,7 +216,6 @@ describe('getPlatformScopeFactory', () => {

it('should return empty scope if error during request to core', async () => {
mockRpcClient.mnsync.withArgs('status').throws(new Error());
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
mockDockerCompose.isServiceRunning.returns(true);
mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_tenderdash')
.returns(DockerStatusEnum.running);
Expand Down Expand Up @@ -268,7 +271,7 @@ describe('getPlatformScopeFactory', () => {
},
},
});
mockDockerCompose.execCommand.returns({ exitCode: 1, out: '' });
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));

const expectedScope = {
Expand Down Expand Up @@ -300,6 +303,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.wait_for_core,
version: '1.4.1',
},
};

Expand All @@ -324,7 +328,7 @@ describe('getPlatformScopeFactory', () => {
.returns(DockerStatusEnum.running);
mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_abci')
.returns(DockerStatusEnum.running);
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));

const expectedScope = {
Expand Down Expand Up @@ -356,6 +360,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '1.4.1',
},
};

Expand All @@ -380,8 +385,11 @@ describe('getPlatformScopeFactory', () => {
.returns(DockerStatusEnum.running);
mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_abci')
.throws(new ContainerIsNotPresentError('drive_abci'));
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
const error = new DockerComposeError({
exitCode: 1,
});
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').rejects(error);

const mockStatus = {
node_info: {
Expand Down Expand Up @@ -434,6 +442,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.not_started,
serviceStatus: ServiceStatusEnum.stopped,
version: null,
},
};

Expand All @@ -454,7 +463,8 @@ describe('getPlatformScopeFactory', () => {
mockDockerCompose.isServiceRunning
.withArgs(config, 'drive_tenderdash')
.returns(true);
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci status').resolves({ exitCode: 0, out: '' });
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
mockDetermineDockerStatus.returns(DockerStatusEnum.running);
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
mockFetch.returns(Promise.reject(new Error('FetchError')));
Expand Down Expand Up @@ -488,6 +498,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '1.4.1',
},
};

Expand Down

0 comments on commit bd518c9

Please sign in to comment.