Skip to content

Commit

Permalink
fix(diagnostics): fix diagnostics replay restart (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
chmeyer-ms authored Dec 13, 2024
1 parent 623301d commit 6af0405
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/panels/minecraft-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export class MinecraftDiagnosticsPanel {
this._panel.webview.onDidReceiveMessage(message => {
switch (message.type) {
case 'restart':
this._statsTracker.stop();
this._panel.webview.html = this._getWebviewContent(
this._panel.webview,
extensionUri,
statsTracker.manualControl()
);
this._statsTracker.stop();
break;
case 'pause':
this._statsTracker.pause();
Expand Down
21 changes: 21 additions & 0 deletions src/stats/replay-stats-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ describe('ReplayStatsProvider', () => {
expect(statCount).toBeGreaterThan(0);
});

it('should restart propertly', async () => {
const replayFilePath = path.resolve('./test/diagnostics-replay-compressed.mcstats');
const replay = new ReplayStatsProvider(replayFilePath);
let statCount = 0;
let statsCallback: StatsListener = {
onStatUpdated: (stat: StatData) => {
statCount++;
expect(stat).toBeDefined();
},
};
replay.addStatListener(statsCallback);
let results = await replay.start();
expect(results.statLinesRead).toBe(3);
expect(results.statEventsSent).toBe(3);
expect(statCount).toBeGreaterThan(0);
replay.stop();
let results2 = await replay.start();
expect(results2.statLinesRead).toBe(3);
expect(results2.statEventsSent).toBe(3);
});

it('should fire notification on invalid file read', async () => {
const replayFilePath = './not-a-real-file.mcstats';
const replay = new ReplayStatsProvider(replayFilePath);
Expand Down
7 changes: 5 additions & 2 deletions src/stats/replay-stats-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export class ReplayStatsProvider extends StatsProvider {
private _simTickPeriod: number;
private _simTickCurrent: number;
private _simTimeoutId: NodeJS.Timeout | null;
private _replayHeader: ReplayStatMessageHeader | undefined;
private _base64Gzipped: boolean;
private _pendingStats: StatMessageModel[];
private _replayHeader: ReplayStatMessageHeader | undefined;
private _replayResults: ReplayResults;
private _onComplete: ((results: ReplayResults) => void) | undefined;

Expand Down Expand Up @@ -52,6 +52,7 @@ export class ReplayStatsProvider extends StatsProvider {
this._simTimeoutId = null;
this._base64Gzipped = false;
this._pendingStats = [];
this._replayHeader = undefined;
this._replayResults = new ReplayResults();
this._onComplete = undefined;
}
Expand Down Expand Up @@ -85,7 +86,6 @@ export class ReplayStatsProvider extends StatsProvider {
}
if (this._onComplete) {
this._onComplete(this._replayResults);
this._onComplete = undefined;
}
if (this._replayStreamReader) {
this._replayStreamReader.close();
Expand All @@ -97,6 +97,9 @@ export class ReplayStatsProvider extends StatsProvider {
this._simTimeoutId = null;
this._base64Gzipped = false;
this._pendingStats = [];
this._replayHeader = undefined;
this._replayResults = new ReplayResults();
this._onComplete = undefined;
}

public override pause() {
Expand Down

0 comments on commit 6af0405

Please sign in to comment.