microsoft / vscode-debugadapter-node

Debug adapter protocol and implementation for VS Code.
Other
273 stars 79 forks source link

[question] tests on debug adapter yields timeout #223

Closed lggomezml closed 3 years ago

lggomezml commented 4 years ago

I'm working on implementing tests for the golang debug adapter and so far I've not been successful based on the available examples

import tsup = require('vscode-debugadapter-testsupport');
import * as Path from 'path';

suite('Go Debug Adapter', () => {
    let dc: tsup.DebugClient;

    const PROJECT_ROOT = Path.join(__dirname, '../../../..');
    const DATA_ROOT = Path.join(PROJECT_ROOT, 'test/fixtures/debug');
    const PROJECT_OUTPUT = Path.join(__dirname, '../..');
    const DEBUG_ADAPTER = Path.join(PROJECT_OUTPUT, 'debugAdapter/goDebug.js');

    setup( () => {
        console.log('setup start');
        dc = new tsup.DebugClient('go', DEBUG_ADAPTER, 'go', undefined, true);
        dc.defaultTimeout = 20000;
        let p = dc.start();
        console.log('setup end');
        return p;
    });

    teardown( () => {
        console.log('teardown');
        dc.stop();
    } );

    suite('basic', () => {
        test('unknown request should produce error', done => {
            const err = new Error('does not report error on unknown request');
            console.log('basic dc.send');
            const r = dc.send('illegal_request');
            r.then(() => {
                console.log('basic dc.then');
                done(err);
            }).catch(() => {
                console.log('basic dc.catch');
                done();
            }).finally(() => {
                console.log('basic dc.finally');
                done(err);
            });

            console.log('basic end');
        });
    });

    suite('launch', () => {
        test('should run program to the end', () => {
            const PROGRAM = Path.join(DATA_ROOT, 'main/main.go');
            return Promise.all([
                dc.configurationSequence(),
                dc.launch({ program: PROGRAM }),
                dc.waitForEvent('terminated')
            ]);
        });
    });
});

And here the output, with extra logs on the debugClient side:

/usr/local/bin/node --inspect-brk=32734 node_modules/mocha/bin/_mocha -u tdd --timeout 5000 --colors /Users/lgomez/DEV/GITHUB/vscode-go/out/src/debugAdapter/tests
Debugger listening on ws://127.0.0.1:32734/e7ebb7eb-0ac1-4271-a601-a2f5f4ac95b7
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

  Go Debug Adapter
    basic
setup start
spawned debug adapter process successfully - runtime:go, executable:/Users/lgomez/DEV/GITHUB/vscode-go/out/src/debugAdapter/goDebug.js
setup end
(node:96217) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
basic dc.send
send called on 'illegal_request' command
doSend: begin write on stream - events:["end"], listeners:undefined'
basic end
stderr: go /Users/lgomez/DEV/GITHUB/vscode-go/out/src/debugAdapter/goDebug.js: unknown command
Run 'go help' for usage.
exiting debug adapter

      1) unknown request should produce error
teardown
send called on 'disconnect' command
doSend: begin write on stream - events:["end"], listeners:undefined'
    launch
setup start
spawned debug adapter process successfully - runtime:go, executable:/Users/lgomez/DEV/GITHUB/vscode-go/out/src/debugAdapter/goDebug.js
setup end
send called on 'initialize' command
doSend: begin write on stream - events:["end"], listeners:undefined'
stderr: go /Users/lgomez/DEV/GITHUB/vscode-go/out/src/debugAdapter/goDebug.js: unknown command
Run 'go help' for usage.
exiting debug adapter

      2) should run program to the end
teardown
send called on 'disconnect' command
doSend: begin write on stream - events:["end"], listeners:undefined'

  0 passing (10s)
  2 failing
  1) Go Debug Adapter
       basic
         unknown request should produce error:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/lgomez/DEV/GITHUB/vscode-go/out/src/debugAdapter/tests/goDebug.test.js)

  2) Go Debug Adapter
       launch
         should run program to the end:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/lgomez/DEV/GITHUB/vscode-go/out/src/debugAdapter/tests/goDebug.test.js)

I can see that it still tries to resolve the go debugger and there aren't any listeners for the command I am trying to test (and also that the defaultTimeout isn't being changed at runtime although that's the lesser issue here) , so is there anything I'm missing for the setup of this particular debug adapter? thanks in advance

suzmue commented 4 years ago

I was able to make this work using dc = new tsup.DebugClient('node', DEBUG_ADAPTER, 'go');

Would it be possible to add some documentation to clarify which runtime is expected as the first argument?