jsii icon indicating copy to clipboard operation
jsii copied to clipboard

exposing a http-tcp-socket from within the subprocess

Open jaecktec opened this issue 3 years ago • 2 comments

:question: Guidance

Affected Languages

  • [ ] TypeScript or Javascript
  • [ ] Python
  • [x] Java
  • [ ] .NET (C#, F#, ...)
  • [ ] Go

General Information

  • JSII Version: 1.35.0 (build 6ebef96), typescript 3.9.10
  • Platform: Darwin xxxx 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64 x86_64

The Question

Hello, I'm trying evaluate the possibility to build a testing library that mocks a http server. I tried some code:

async start(): Promise<any> {
    this._server = createServer({}, (req, res) => {
      this._requestHandler(req, res);
    });
    return new Promise((resolve) => {
      this._server!.listen(8080, () => {
        console.log('server started')
        resolve(null);
      });
    });
  }

this works fine in node, however it seems I can't get a connection from my junit test:

// ktor
val httpClient = HttpClient(CIO)
val content = runBlocking {
    httpClient.request<String> {
        timeout { requestTimeoutMillis = 1000 }
        url(Url("http://localhost:8080/hello/world"))
        method = Get
    }
}

I've also hit an infinite sleep in the junit test and tried to curl the local address, however with no success.

could it be that it is not possible to expose a socket from the internal node process?

jaecktec avatar Oct 03 '21 21:10 jaecktec

Async invocations are likely buggy in most languages, as these implementations have not been used in the wild so far, as far as I know. It might take a while to make them actually usable for this purpose...

This isn't currently the main area of focus for the team, so I don't think you should expect to see much movement coming from our side of the fence on this domain in the near future... That being said I'd be happy to take pull requests if you have some free time and are feeling brave (I'm happy to provide guidance, too).

RomainMuller avatar Oct 05 '21 10:10 RomainMuller

I have this exact case (building a testing library that mocks an http server) - I'd be happy to look in to this more if there is a good place to start looking. I think #4133 is related (and a possible cause), too.

TimothyJones avatar Jun 07 '23 08:06 TimothyJones