aws / jsii

jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
https://aws.github.io/jsii
Apache License 2.0
2.66k stars 246 forks source link

exposing a http-tcp-socket from within the subprocess #3016

Open jaecktec opened 3 years ago

jaecktec commented 3 years ago

:question: Guidance

Affected Languages

General Information

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?

RomainMuller commented 3 years ago

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).

TimothyJones commented 1 year ago

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.