Skip to content

Commit f70c0f7

Browse files
authored
fix(rosetta): flakey trim-cache test (#4043)
It appears the trim-cache test using tablet compression occasionally fails in CI/CD. I suspect this is due to the `save` function returning before the GZip stream has bene closed, resulting in the subsequent read attempting to consume an incomplete GZip object. This adds the necessary provisions to ensure the GZip stream is closed (or failed) before `save` returns. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
1 parent 6086b34 commit f70c0f7

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

packages/jsii-rosetta/lib/json.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Readable, Writable, pipeline } from 'node:stream';
1+
import { Readable, pipeline } from 'node:stream';
22
import { promisify } from 'node:util';
33
import { parser } from 'stream-json';
44
import * as Assembler from 'stream-json/Assembler';
@@ -36,12 +36,15 @@ export async function parse(reader: Readable): Promise<any> {
3636
* better performance.
3737
*
3838
* @param value the value to be serialized.
39-
* @param writer the write in which to write the JSON text.
39+
* @param writers the sequence of write streams to use to output the JSON text.
4040
*/
41-
export async function stringify(value: any, writer: Writable): Promise<void> {
41+
export async function stringify(
42+
value: any,
43+
...writers: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream>
44+
): Promise<void> {
4245
const reader = new Readable({ objectMode: true });
4346
reader.push(value);
4447
reader.push(null);
4548

46-
return asyncPipeline(reader, disassembler(), stringer(), writer);
49+
return asyncPipeline(reader, disassembler(), stringer(), ...writers);
4750
}

packages/jsii-rosetta/lib/tablets/tablets.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,13 @@ export class LanguageTablet {
182182
* Saves the tablet schema to a file. If the compress option is passed, then
183183
* the schema will be gzipped before writing to the file.
184184
*/
185-
public async save(filename: string, compress = false) {
185+
public async save(filename: string, compress = false): Promise<void> {
186186
await fs.mkdir(path.dirname(filename), { recursive: true });
187187

188188
const writeStream: Writable = createWriteStream(filename, { flags: 'w' });
189189
const gzip = compress ? zlib.createGzip() : undefined;
190-
gzip?.pipe(writeStream, { end: true });
191190

192-
return stringify(this.toSchema(), gzip ?? writeStream);
191+
return stringify(this.toSchema(), ...(gzip ? [gzip] : []), writeStream);
193192
}
194193

195194
private toSchema(): TabletSchema {

0 commit comments

Comments
 (0)