|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// This tests that a local TCP server can be snapshotted and the |
| 4 | +// diagnostics channels work across serialization. |
| 5 | + |
| 6 | +require('../common'); |
| 7 | +const assert = require('assert'); |
| 8 | +const { spawnSync } = require('child_process'); |
| 9 | +const tmpdir = require('../common/tmpdir'); |
| 10 | +const fixtures = require('../common/fixtures'); |
| 11 | +const path = require('path'); |
| 12 | +const fs = require('fs'); |
| 13 | + |
| 14 | +tmpdir.refresh(); |
| 15 | +const blobPath = path.join(tmpdir.path, 'snapshot.blob'); |
| 16 | +const entry = fixtures.path('snapshot', 'server.js'); |
| 17 | +{ |
| 18 | + const child = spawnSync(process.execPath, [ |
| 19 | + '--snapshot-blob', |
| 20 | + blobPath, |
| 21 | + '--build-snapshot', |
| 22 | + entry, |
| 23 | + ], { |
| 24 | + cwd: tmpdir.path |
| 25 | + }); |
| 26 | + if (child.status !== 0) { |
| 27 | + console.log(child.stderr.toString()); |
| 28 | + console.log(child.stdout.toString()); |
| 29 | + assert.strictEqual(child.status, 0); |
| 30 | + } |
| 31 | + const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob')); |
| 32 | + assert(stats.isFile()); |
| 33 | +} |
| 34 | + |
| 35 | +{ |
| 36 | + const child = spawnSync(process.execPath, [ |
| 37 | + '--snapshot-blob', |
| 38 | + blobPath, |
| 39 | + ], { |
| 40 | + cwd: tmpdir.path, |
| 41 | + env: { |
| 42 | + ...process.env, |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + const stdout = child.stdout.toString().trim(); |
| 47 | + console.log(`[stdout]:\n${stdout}\n`); |
| 48 | + const stderr = child.stderr.toString().trim(); |
| 49 | + console.log(`[stderr]:\n${stderr}\n`); |
| 50 | + assert.strictEqual(child.status, 0); |
| 51 | + |
| 52 | + const lines = stdout.split('\n'); |
| 53 | + assert.strictEqual(lines.length, 4); |
| 54 | + |
| 55 | + // The log should look like this: |
| 56 | + // server port ${port} |
| 57 | + // From client diagnostics channel |
| 58 | + // From server diagnostics channel: ${port} |
| 59 | + // recv.length: 256 |
| 60 | + assert.match(lines[0], /server port (\d+)/); |
| 61 | + const port = lines[0].match(/server port (\d+)/)[1]; |
| 62 | + assert.match(lines[1], /From client diagnostics channel/); |
| 63 | + assert.match(lines[2], new RegExp(`From server diagnostics channel: ${port}`)); |
| 64 | + assert.match(lines[3], /recv\.length: 256/); |
| 65 | +} |
0 commit comments