Add test to BasicActionRunnerTests to confirm runtime supports global state
- Dominant language
- Scala
- Stars
- 6.8k
- Forks
- 1.2k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 2
Description
## Environment details:
* native ubuntu
## Steps to reproduce the issue:
I've tested whether global variables could be reused when container was reused.
The test results show that only nodejs runtime can reuse global scope variable.
The AWS Lambda service is not stateless for all runtimes. (it means an action can reuse global variable if container is reused)
Is there any OW spec for a global variable?
### 1. Javascript
```javascript
let globalCache = {};
function main(params) {
globalCache[getRandom()] = getRandom();
return globalCache;
}
function getRandom() {
return Math.random();
}
```
If the container is reused, the global variable is reused.
```json
{
"0.25746017280185063": 0.7853652208888477
}
```
```json
{
"0.25746017280185063": 0.7853652208888477,
"0.4376083800717476": 0.6122601078429637
}
```
### 2. PHP
```php
$GLOBALS['count']];
}
```
The global variable is not retained even if the container is reused. (Only returns 1)
```json
{
"count": 1
}
```
### 3. Python
```python
g = 0
def main(args):
try:
global g
g = g + 1
return {"count": g}
except Exception as e:
# please handle exception here
# you can return or hide an error message
return {"error": str(e)}
```
The global variable is not retained even if the container is reused. (Only returns 1)
**If you run the same code in AWS Lambda, the count will increase.**
```json
{
"count": 1
}
```
### 4. Java
The static variable is not retained even if the container is reused. (counter variable is always 1)
```java
class Global {
public static int counter = 0;
}
public class Application {
public static JsonObject main(JsonObject args) {
Global.counter++;
System.out.println(String.valueOf(Global.counter));
return null;
}
}
```
#### log
```
1
```
Contributor guide
Research direction
Start by locating BasicActionRunnerTests and reading its existing runtime coverage and test setup. Add a test covering reuse of global or static state across invocations for the runtimes described in the issue, then run that test suite and verify the observed behavior is recorded consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript, php, python
- Domain
- backend, testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100