-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(diagnostics): support compressed .mcstats streams, add tests for…
… processing stream. (#273) - tests for ReplayStatsProvider - optional support for base64 encoded gzip diag file. MC will always produce this type.
- Loading branch information
1 parent
c7fd5c7
commit 623301d
Showing
9 changed files
with
205 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { ReplayStatsProvider } from './replay-stats-provider'; | ||
import { StatData, StatsListener } from './stats-provider'; | ||
import path from 'path'; | ||
|
||
describe('ReplayStatsProvider', () => { | ||
it('should load base64-gzip encoded replay data and trigger events', 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); // no idea how many are in there | ||
}); | ||
|
||
it('should load uncompressed replay and trigger events', async () => { | ||
const replayFilePath = path.resolve('./test/diagnostics-replay-uncompressed.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); | ||
}); | ||
|
||
it('should load no-header uncompressed replay and trigger events', async () => { | ||
const replayFilePath = path.resolve('./test/diagnostics-replay-uncompressed-no-header.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); | ||
}); | ||
|
||
it('should fire notification on invalid file read', async () => { | ||
const replayFilePath = './not-a-real-file.mcstats'; | ||
const replay = new ReplayStatsProvider(replayFilePath); | ||
let notification = ''; | ||
let statsCallback: StatsListener = { | ||
onNotification: (message: string) => { | ||
notification = message; | ||
}, | ||
}; | ||
replay.addStatListener(statsCallback); | ||
let results = await replay.start(); | ||
expect(results.statLinesRead).toBe(0); | ||
expect(notification).toBe('Failed to read replay file.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"encoding":"base64-gzip"} | ||
H4sIAAAAAAAACq2RMQvCMBCF/0q5ORRaULSbQ3EVlDqIyJEebTBeS3JVRPzvJg4iiIPS8fE+vntwNxCjj1BM5rNsMs0VyLUnKGAtKOWZWHJQ4EPwUOxuwHiKbYtcWzrobuBQKNCtsbUjfmcaYnIonUuEvHyBShYj11Ce0Q4Ub2T5/r6/qxdRIRtrMVmGuAkinyxs3+J4vhGXVdnfsi06j5cRVjny3eA0rVAfU6oHjWI6TpvQxj+kT+w3+bueImPIf1IP7xkEAUoCAAA= | ||
H4sIAAAAAAAACq2SzWrDMBCEX8XoLEzkn6TxLYfQa6ElPRQTtvJiq5ElI61dQsi7V84hGIyhLbkIlhl9O1rthZGSJ1bk2yeRr1PO6NwhK9grAe0HNJQwznwoPCs+LsxAO6oNmErjUdreBIEz2ShdOTRTT40GHZB1EaGnBdPekKJzEAfQPY49RFJeyyu/Ow5glNYQPYfyLYB8tNNdA4/jPTDZQfwb9g7Ow/cDUjn0tncSX0CeYqx6CaSsieugjv8Q32x/g0/xHt2A7jguTThaZeqlqBoH1DfjlJjlK8EzscnL+6q1SjrrUVpTeTZtJZ3qaEbYrNZ8vc1+ff/Lfs4YQohkxZM0Txc500fjOBiFfj6aH/azqd4/AwAA | ||
H4sIAAAAAAAACq2RQQuCQBCF/4rMWQSlorx1kK5BUYeQGNZBl7YxdsdCxP/e2iGE6FB4fLyPbx5MB6LVBdL5ahnPF7MQpL0RpLATlOxOLAmE4HxwkJ46YLwObYVcGDqrumFfhKAqbQpLPGZKYrIotQ2EnHyBMhYtrS/vaBoabsRJ3ud9+CYOyNoYDDY+7r3IBWtzq3A634TLDvHfsiNah48JVllydWMVbVFdIioahaJrjkrfDn+IXthv8rGeBkaT+6SeqVlmQ0oCAAA= |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.