Files
Xen-Orchestra-xen-orchestra…/@xen-orchestra/vmware-explorer/_nbdkit.integ.mjs
Florent BEAUCHAMP 3bf50c38ee fix(vmware-explorer): fixes omnibus (#10363)
This branch is a reliability overhaul of the ESXi/vSphere source side of V2V, plus a scope reduction of the package. The SOAP plumbing is rewritten:

    VimClient wraps @vates/node-vsphere-soap in a promise API with one emitter per call (no more cross-talk between concurrent calls, no listener leak) and a pTimeout;
    vim25 faults are now parsed (_parseFault.mjs) so callers get a real fault type instead of task execution failed;
    the library no longer throws from async callbacks (which killed xo-server) and its beforeExit logout hook is per-client instead of removeAllListeners.
    Request specs are built in explicit schema order (soap/specs.mjs) with xsi:type, and property values are normalized (soap/normalize.mjs) so search() and the new #retrieveProperty share one shape.
    search() now paginates, cancels the retrieval and destroys the container view.
    Datastore HTTP downloads get session-cookie reuse, retry with jittered backoff, a headers-only timeout, and range-honouring validation.
    Task waiting polls with backoff and per-operation timeouts (6 h for snapshot consolidation).
    nbdkit servers are memoized by a key that includes the export options, the readiness wait races the process death instead of sleeping 2 s
    the password file is 0600 and unlinked
    the thumbprint is read over TLS in-process instead of two openssl spawns.
    The old VHD-over-datastore readers (VhdEsxi*, Datastore*, openDeltaVmdkAsVhd) are deleted, hence the majo, rleaving the vddk/NBD path with a COWD grain-directory parser as data-map fallback.
    ~1.7k lines of unit tests are added.
2026-09-11 17:36:38 +02:00

56 lines
1.7 KiB
JavaScript

import assert from 'node:assert/strict'
import { createServer } from 'node:net'
import { describe, it } from 'node:test'
import { findFreePort, waitForPort } from './_nbdkit.mjs'
// these bind a real port
describe('findFreePort', function () {
it('returns a port which can be bound', async function () {
const port = await findFreePort()
assert.equal(typeof port, 'number')
const server = createServer()
await new Promise((resolve, reject) => {
server.once('error', reject)
server.listen(port, '127.0.0.1', resolve)
})
server.close()
})
})
describe('waitForPort', function () {
it('resolves as soon as the port accepts a connection', async function () {
const port = await findFreePort()
const server = createServer()
// start listening later, as nbdkit does once its plugin is configured
const timer = setTimeout(() => server.listen(port, '127.0.0.1'), 30)
try {
await waitForPort(port, { probeDelay: 5, timeout: 2e3 })
} finally {
clearTimeout(timer)
server.close()
}
})
it('gives up with the reason of the last attempt', async function () {
const port = await findFreePort()
await assert.rejects(waitForPort(port, { probeDelay: 1, timeout: 20 }), error => {
assert.match(error.message, /nothing is listening on 127\.0\.0\.1:/)
assert.equal(error.code, 'NBDKIT_NOT_LISTENING')
assert.equal(error.cause.code, 'ECONNREFUSED')
return true
})
})
it('stops probing when aborted', async function () {
const port = await findFreePort()
await assert.rejects(waitForPort(port, { probeDelay: 1, signal: AbortSignal.abort(), timeout: 1e3 }), {
name: 'AbortError',
})
})
})