Skip to content

fix(diagnostics): fix diagnostics replay restart #274

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

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading