Skip to content

Add tests for BoardsServiceProvider #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add "uploadInProgress" prop to boards change event
  • Loading branch information
davegarthsimpson committed Aug 16, 2022
commit e9137f79663af52526bb873d35569e032b45ab59
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
protected _availablePorts: Port[] = [];
protected _availableBoards: AvailableBoard[] = [];

private uploadAttemptInProgress = false;

private lastItemRemovedForUpload: { board: Board; port: Port } | undefined;
// "lastPersistingUploadPort", is a port created during an upload, that persisted after
// the upload finished, it's "substituting" the port selected when the user invoked the upload
Expand All @@ -87,9 +85,6 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
private readonly _reconciled = new Deferred<void>();

onStart(): void {
this.notificationCenter.onUploadAttemptInProgress(
this.onUploadAttemptEventReceived.bind(this)
);
this.notificationCenter.onAttachedBoardsDidChange(
this.notifyAttachedBoardsChanged.bind(this)
);
Expand Down Expand Up @@ -121,10 +116,6 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
return this._reconciled.promise;
}

private onUploadAttemptEventReceived(uploadAttemptInProgress: boolean): void {
this.uploadAttemptInProgress = uploadAttemptInProgress;
}

private checkForItemRemoved(event: AttachedBoardsChangeEvent): void {
if (!this.lastItemRemovedForUpload) {
const {
Expand Down Expand Up @@ -192,7 +183,9 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
this.logger.info('------------------------------------------');
}

if (this.uploadAttemptInProgress) {
const { uploadInProgress } = event;

if (uploadInProgress) {
this.checkForItemRemoved(event);
} else {
this.checkForPersistingPort(event);
Expand All @@ -202,7 +195,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
this._availablePorts = event.newState.ports;
this.onAvailablePortsChangedEmitter.fire(this._availablePorts);
this.reconcileAvailableBoards().then(() => {
if (!this.uploadAttemptInProgress) {
if (!uploadInProgress) {
this.tryReconnect();
}
});
Expand Down
10 changes: 1 addition & 9 deletions arduino-ide-extension/src/browser/notification-center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class NotificationCenter
}>();
private readonly onAppStateDidChangeEmitter =
new Emitter<FrontendApplicationState>();
private readonly onUploadAttemptInProgressEmitter = new Emitter<boolean>();

protected readonly toDispose = new DisposableCollection(
this.indexWillUpdateEmitter,
Expand All @@ -80,8 +79,7 @@ export class NotificationCenter
this.platformDidUninstallEmitter,
this.libraryDidInstallEmitter,
this.libraryDidUninstallEmitter,
this.attachedBoardsDidChangeEmitter,
this.onUploadAttemptInProgressEmitter
this.attachedBoardsDidChangeEmitter
);

readonly onIndexDidUpdate = this.indexDidUpdateEmitter.event;
Expand All @@ -99,8 +97,6 @@ export class NotificationCenter
this.attachedBoardsDidChangeEmitter.event;
readonly onRecentSketchesDidChange = this.recentSketchesChangedEmitter.event;
readonly onAppStateDidChange = this.onAppStateDidChangeEmitter.event;
readonly onUploadAttemptInProgress =
this.onUploadAttemptInProgressEmitter.event;

@postConstruct()
protected init(): void {
Expand Down Expand Up @@ -173,8 +169,4 @@ export class NotificationCenter
notifyRecentSketchesDidChange(event: { sketches: Sketch[] }): void {
this.recentSketchesChangedEmitter.fire(event);
}

notifyUploadAttemptInProgress(event: boolean): void {
this.onUploadAttemptInProgressEmitter.fire(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export namespace AvailablePorts {
export interface AttachedBoardsChangeEvent {
readonly oldState: Readonly<{ boards: Board[]; ports: Port[] }>;
readonly newState: Readonly<{ boards: Board[]; ports: Port[] }>;
readonly uploadInProgress: boolean;
}
export namespace AttachedBoardsChangeEvent {
export function isEmpty(event: AttachedBoardsChangeEvent): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export interface NotificationServiceClient {
notifyLibraryDidUninstall(event: { item: LibraryPackage }): void;
notifyAttachedBoardsDidChange(event: AttachedBoardsChangeEvent): void;
notifyRecentSketchesDidChange(event: { sketches: Sketch[] }): void;
notifyUploadAttemptInProgress(event: boolean): void;
}

export const NotificationServicePath = '/services/notification-service';
Expand Down
7 changes: 7 additions & 0 deletions arduino-ide-extension/src/node/board-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class BoardDiscovery
private readonly onStreamDidCancelEmitter = new Emitter<void>(); // when the watcher is canceled by the IDE2
private readonly toDisposeOnStopWatch = new DisposableCollection();

private uploadInProgress = false;

/**
* Keys are the `address` of the ports.
*
Expand Down Expand Up @@ -123,6 +125,10 @@ export class BoardDiscovery
});
}

public setUploadInProgress(uploadAttemptInProgress: boolean): void {
this.uploadInProgress = uploadAttemptInProgress;
}

private createTimeout(
after: number,
onTimeout: (error: Error) => void
Expand Down Expand Up @@ -318,6 +324,7 @@ export class BoardDiscovery
ports: newAvailablePorts,
boards: newAttachedBoards,
},
uploadInProgress: this.uploadInProgress,
};

this._availablePorts = newState;
Expand Down
6 changes: 6 additions & 0 deletions arduino-ide-extension/src/node/core-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Instance } from './cli-protocol/cc/arduino/cli/commands/v1/common_pb';
import { firstToUpperCase, notEmpty } from '../common/utils';
import { ServiceError } from './service-error';
import { ExecuteWithProgress, ProgressResponse } from './grpc-progressible';
import { BoardDiscovery } from './board-discovery';

namespace Uploadable {
export type Request = UploadRequest | UploadUsingProgrammerRequest;
Expand All @@ -51,6 +52,9 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
@inject(CommandService)
private readonly commandService: CommandService;

@inject(BoardDiscovery)
protected readonly boardDiscovery: BoardDiscovery;

async compile(options: CoreService.Options.Compile): Promise<void> {
const coreClient = await this.coreClient;
const { client, instance } = coreClient;
Expand Down Expand Up @@ -378,6 +382,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
fqbn?: string | undefined;
port?: Port | undefined;
}): Promise<void> {
this.boardDiscovery.setUploadInProgress(true);
return this.monitorManager.notifyUploadStarted(fqbn, port);
}

Expand All @@ -388,6 +393,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
fqbn?: string | undefined;
port?: Port | undefined;
}): Promise<Status> {
this.boardDiscovery.setUploadInProgress(false);
return this.monitorManager.notifyUploadFinished(fqbn, port);
}

Expand Down