Skip to content

Commit

Permalink
NAS-128601: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanY147 committed Oct 11, 2024
1 parent 7674566 commit 0bdb8a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/app/services/gpu/gpu-service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { Store } from '@ngrx/store';
import { provideMockStore } from '@ngrx/store/testing';
import { firstValueFrom } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
Expand All @@ -9,6 +10,7 @@ import { AdvancedConfig } from 'app/interfaces/advanced-config.interface';
import { Device } from 'app/interfaces/device.interface';
import { GpuService } from 'app/services/gpu/gpu.service';
import { WebSocketService } from 'app/services/ws.service';
import { advancedConfigUpdated } from 'app/store/system-config/system-config.actions';
import { selectAdvancedConfig } from 'app/store/system-config/system-config.selectors';

describe('GpuService', () => {
Expand All @@ -35,6 +37,10 @@ describe('GpuService', () => {
mockWebSocket([
mockCall('system.advanced.update_gpu_pci_ids'),
mockCall('device.get_info', allGpus),
mockCall('system.advanced.get_gpu_pci_choices', {
'GeForce [0000:01:00.0]': '0000:01:00.0',
'Radeon [0000:02:00.0]': '0000:02:00.0',
}),
]),
provideMockStore({
selectors: [
Expand Down Expand Up @@ -65,10 +71,12 @@ describe('GpuService', () => {

describe('getGpuOptions', () => {
it('returns an observable with a list of options for GPU select', async () => {
const store$ = spectator.inject(Store);
jest.spyOn(store$, 'dispatch');
const options = await firstValueFrom(spectator.service.getGpuOptions());
expect(options).toEqual([
{ label: 'GeForce', value: '0000:01:00.0' },
{ label: 'Radeon', value: '0000:02:00.0' },
{ label: 'GeForce [0000:01:00.0]', value: '0000:01:00.0' },
{ label: 'Radeon [0000:02:00.0]', value: '0000:02:00.0' },
]);
});
});
Expand All @@ -94,12 +102,15 @@ describe('GpuService', () => {

describe('addIsolatedGpuPciIds', () => {
it('adds new ids of new isolated gpu devices in addition to ones that were previously isolated', async () => {
const store$ = spectator.inject(Store);
jest.spyOn(store$, 'dispatch');
await firstValueFrom(spectator.service.addIsolatedGpuPciIds(['0000:01:00.0']));

expect(spectator.inject(WebSocketService).call).toHaveBeenCalledWith(
'system.advanced.update_gpu_pci_ids',
[['0000:02:00.0', '0000:01:00.0']],
);
expect(spectator.inject(Store).dispatch).toHaveBeenCalledWith(advancedConfigUpdated());
});

it('does nothing when new gpu has already been isolated', () => {
Expand Down
7 changes: 6 additions & 1 deletion src/app/services/gpu/gpu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
} from 'rxjs';
import {
map, shareReplay, switchMap, take,
tap,
} from 'rxjs/operators';
import { DeviceType } from 'app/enums/device-type.enum';
import { Device } from 'app/interfaces/device.interface';
import { Option } from 'app/interfaces/option.interface';
import { WebSocketService } from 'app/services/ws.service';
import { AppState } from 'app/store';
import { advancedConfigUpdated } from 'app/store/system-config/system-config.actions';
import { waitForAdvancedConfig } from 'app/store/system-config/system-config.selectors';

@Injectable({
Expand Down Expand Up @@ -82,8 +84,11 @@ export class GpuService {
return EMPTY;
}

return this.ws.call('system.advanced.update_gpu_pci_ids', [Array.from(newIsolatedGpuIds)]);
return this.ws.call('system.advanced.update_gpu_pci_ids', [Array.from(newIsolatedGpuIds)]).pipe(
tap(() => this.store$.dispatch(advancedConfigUpdated())),
);
}),

);
}
}

0 comments on commit 0bdb8a1

Please sign in to comment.