Skip to content

Commit 381ae70

Browse files
committed
fix(python-runtime): add compliance test for async context callbacks
1 parent 863b19b commit 381ae70

File tree

4 files changed

+177
-15
lines changed

4 files changed

+177
-15
lines changed

CONTRIBUTING.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Contributing to jsii
2+
23
Thanks for your interest in contributing to AWS JSII! :heart:
34

45
This document describes how to set up a development environment and submit your
56
contributions. Please read it carefully and let us know if it's not up-to date
67
(or even better, submit a pull request with your corrections! :wink:).
78

89
## Pre-requisites
10+
911
### Setup Docker image
12+
1013
Due to the polyglot nature of `jsii`, the toolchain requirements are somewhat
1114
more complicated than for most projects. In order to locally develop `jsii`, you
1215
will need a number of tools.
@@ -19,37 +22,38 @@ our own CI/CD: the ["superchain" image][superchain] from.
1922
The image can be built for local usage, too:
2023

2124
```console
22-
$ IMAGE=superchain
23-
$ docker build -t ${IMAGE} ./superchain
25+
IMAGE=superchain
26+
docker build -t ${IMAGE} ./superchain
2427
```
2528

2629
In order to get an interactive shell within a Docker container using the
2730
*superchain* image you just built:
2831

2932
```console
30-
$ cd jsii # go to the root of the jsii repo
31-
$ docker run --rm --net=host -it -v $PWD:$PWD -w $PWD ${IMAGE}
33+
cd jsii # go to the root of the jsii repo
34+
docker run --rm --net=host -it -v $PWD:$PWD -w $PWD ${IMAGE}
3235
```
3336

3437
In the shell that pops up, the `npm run` commands in the following sections must
3538
be executed.
3639

3740
### Alternative: Manually install the toolchain
41+
3842
The following tools need to be installed to develop on JSII locally. We recommend
3943
using the docker image from the above section, but if you wish to, you can install
4044
in your development environment.
4145

4246
- [Node `14.6.0`] or later
4347
- [Yarn `1.19.1`] or later
4448
- An OpenJDK-8 distribution (e.g: [Oracle's OpenJDK8], [Amazon Corretto 8])
45-
+ [`maven >= 3.0.5`](https://maven.apache.org)
49+
- [`maven >= 3.0.5`](https://maven.apache.org)
4650
- [.NET Core `3.1`] or later
47-
+ *Recommended:* [`mono >= 5`](https://www.mono-project.com)
51+
- *Recommended:* [`mono >= 5`](https://www.mono-project.com)
4852
- [Python `3.7.3`] or later
49-
+ [`pip`](https://pip.pypa.io/en/stable/installing/)
50-
+ [`setuptools >= 38.6.0`](https://pypi.org/project/setuptools/)
51-
+ [`wheel`](https://pypi.org/project/wheel/)
52-
+ *Recommended:* [`twine`](https://pypi.org/project/twine/)
53+
- [`pip`](https://pip.pypa.io/en/stable/installing/)
54+
- [`setuptools >= 38.6.0`](https://pypi.org/project/setuptools/)
55+
- [`wheel`](https://pypi.org/project/wheel/)
56+
- *Recommended:* [`twine`](https://pypi.org/project/twine/)
5357
- [Go] `1.18` or newer
5458

5559
[Node `14.6.0`]: https://nodejs.org/download/release/v14.6.0/
@@ -61,14 +65,15 @@ in your development environment.
6165
[Go]: https://go.dev/dl/
6266

6367
## Getting Started
68+
6469
### Bootstrapping
6570

6671
The project is managed as a [monorepo] using [lerna].
6772

6873
[monorepo]: https://github.com/babel/babel/blob/main/doc/design/monorepo.md
6974
[lerna]: https://github.com/lerna/lerna
7075

71-
1. Check out this respository and change directory to its root.
76+
1. Check out this repository and change directory to its root.
7277
2. Run `yarn install && yarn build` to install lerna, bootstrap the repository
7378
and perform an initial build and test cycle.
7479

@@ -140,10 +145,10 @@ The runtime client library should be implemented as a module under
140145

141146
The jsii runtime client library usually includes the following components:
142147

143-
- Child process manager: responsible to start/stop the **@jsii/runtime** child
148+
- Child process manager: responsible to start/stop the __@jsii/runtime__ child
144149
process.
145150
- Protocol layer: implements the STDIN/STDOUT protocol that interacts with the
146-
**@jsii/runtime**.
151+
__@jsii/runtime__.
147152
- Proxy layer: includes base classes and serialization utilities to implement
148153
the generated proxy classes.
149154

@@ -163,6 +168,7 @@ The [Python](./packages/jsii-pacmak/lib/targets/python.ts) target is a good
163168
example to work from.
164169

165170
## Releasing
171+
166172
### The `jsii/superchain` Docker image
167173

168174
Upon merging new changes to the `main` branch, the `jsii/superchain:nightly`

packages/@jsii/python-runtime/tests/test_compliance.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
AnonymousImplementationProvider,
7878
UpcasingReflectable,
7979
PromiseNothing,
80+
IPromiseProducer,
81+
ImplementationFromAsyncContext,
8082
)
8183
from jsii_calc.cdk16625 import Cdk16625
8284
from jsii_calc.cdk22369 import AcceptsPath
@@ -1361,5 +1363,19 @@ def test_void_returning_async():
13611363
"""Verifies it's okay to return a Promise<void>."""
13621364

13631365
assert PromiseNothing().instance_promise_it() is None
1364-
## TODO: This is currently broken as code-gen is incorrect for static async.
1366+
# TODO: This is currently broken as code-gen is incorrect for static async.
13651367
# assert PromiseNothing.promise_it() is None
1368+
1369+
1370+
def test_calling_implementation_from_async_context():
1371+
@jsii.implements(IPromiseProducer)
1372+
class ConcreteProducer:
1373+
def produce(self) -> str:
1374+
return "result"
1375+
1376+
producer = ConcreteProducer()
1377+
1378+
assert producer.produce() == "result"
1379+
1380+
worker = ImplementationFromAsyncContext(producer)
1381+
assert worker.do_async_work() == "result"

packages/jsii-calc/lib/compliance.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,3 +3141,28 @@ export class PromiseNothing {
31413141
return PromiseNothing.promiseIt();
31423142
}
31433143
}
3144+
3145+
/**
3146+
* Async Context operations
3147+
* Validates features work when run from within an async context
3148+
*
3149+
* @see https://github.com/aws/jsii/issues/3917
3150+
*/
3151+
export interface IPromiseProducer {
3152+
produce(): Promise<string>;
3153+
}
3154+
3155+
export class ImplementationFromAsyncContext {
3156+
public constructor(private readonly producer: IPromiseProducer) {}
3157+
3158+
public async doAsyncWork(): Promise<string> {
3159+
await this.sleep(200);
3160+
return this.producer.produce();
3161+
}
3162+
3163+
private async sleep(ms: number) {
3164+
return new Promise((resolve) => {
3165+
setTimeout(resolve, ms);
3166+
});
3167+
}
3168+
}

packages/jsii-calc/test/assembly.jsii

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7915,6 +7915,57 @@
79157915
],
79167916
"symbolId": "lib/compliance:IPrivatelyImplemented"
79177917
},
7918+
"jsii-calc.IPromiseProducer": {
7919+
"assembly": "jsii-calc",
7920+
"docs": {
7921+
"see": "https://github.com/aws/jsii/issues/3917",
7922+
"stability": "stable",
7923+
"summary": "Async Context operations Validates features work when run from within an async context."
7924+
},
7925+
"fqn": "jsii-calc.IPromiseProducer",
7926+
"kind": "interface",
7927+
"locationInModule": {
7928+
"filename": "lib/compliance.ts",
7929+
"line": 3151
7930+
},
7931+
"methods": [
7932+
{
7933+
"abstract": true,
7934+
"async": true,
7935+
"docs": {
7936+
"stability": "stable"
7937+
},
7938+
"locationInModule": {
7939+
"filename": "lib/compliance.ts",
7940+
"line": 3153
7941+
},
7942+
"name": "later",
7943+
"returns": {
7944+
"type": {
7945+
"primitive": "string"
7946+
}
7947+
}
7948+
},
7949+
{
7950+
"abstract": true,
7951+
"docs": {
7952+
"stability": "stable"
7953+
},
7954+
"locationInModule": {
7955+
"filename": "lib/compliance.ts",
7956+
"line": 3152
7957+
},
7958+
"name": "now",
7959+
"returns": {
7960+
"type": {
7961+
"primitive": "string"
7962+
}
7963+
}
7964+
}
7965+
],
7966+
"name": "IPromiseProducer",
7967+
"symbolId": "lib/compliance:IPromiseProducer"
7968+
},
79187969
"jsii-calc.IPublicInterface": {
79197970
"assembly": "jsii-calc",
79207971
"docs": {
@@ -8275,6 +8326,70 @@
82758326
],
82768327
"symbolId": "lib/compliance:Implementation"
82778328
},
8329+
"jsii-calc.ImplementationFromAsyncContext": {
8330+
"assembly": "jsii-calc",
8331+
"docs": {
8332+
"stability": "stable"
8333+
},
8334+
"fqn": "jsii-calc.ImplementationFromAsyncContext",
8335+
"initializer": {
8336+
"docs": {
8337+
"stability": "stable"
8338+
},
8339+
"locationInModule": {
8340+
"filename": "lib/compliance.ts",
8341+
"line": 3157
8342+
},
8343+
"parameters": [
8344+
{
8345+
"name": "producer",
8346+
"type": {
8347+
"fqn": "jsii-calc.IPromiseProducer"
8348+
}
8349+
}
8350+
]
8351+
},
8352+
"kind": "class",
8353+
"locationInModule": {
8354+
"filename": "lib/compliance.ts",
8355+
"line": 3156
8356+
},
8357+
"methods": [
8358+
{
8359+
"async": true,
8360+
"docs": {
8361+
"stability": "stable"
8362+
},
8363+
"locationInModule": {
8364+
"filename": "lib/compliance.ts",
8365+
"line": 3164
8366+
},
8367+
"name": "doAsyncStuff",
8368+
"returns": {
8369+
"type": {
8370+
"primitive": "string"
8371+
}
8372+
}
8373+
},
8374+
{
8375+
"docs": {
8376+
"stability": "stable"
8377+
},
8378+
"locationInModule": {
8379+
"filename": "lib/compliance.ts",
8380+
"line": 3159
8381+
},
8382+
"name": "doNormalStuff",
8383+
"returns": {
8384+
"type": {
8385+
"primitive": "string"
8386+
}
8387+
}
8388+
}
8389+
],
8390+
"name": "ImplementationFromAsyncContext",
8391+
"symbolId": "lib/compliance:ImplementationFromAsyncContext"
8392+
},
82788393
"jsii-calc.ImplementsInterfaceWithInternal": {
82798394
"assembly": "jsii-calc",
82808395
"docs": {
@@ -18843,5 +18958,5 @@
1884318958
}
1884418959
},
1884518960
"version": "3.20.120",
18846-
"fingerprint": "EH7xszNdCh9PCFUZ8Foi7g2CPhdrKeZm8CQaUCNv4GQ="
18961+
"fingerprint": "58WxrqNJMJE1Z4D13CRDxszUEaNF5LoQvvnv4eQBygg="
1884718962
}

0 commit comments

Comments
 (0)