-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: bal test
does not exit when a module has a listener declaration and a continuously running worker/asynchronous function
#41213
Comments
As a workaround we can do the following by handling the listener dynamically by ourselves. Edit the module code as follows. import ballerina/http;
import ballerina/lang.runtime;
// remove the listener keyword here
http:Listener httpListener = check new(8080);
// add the service as an service object declared in the module
http:Service serviceObj = service object {
resource function get greeting() returns string {
return "Hello, World!";
}
};
function detachAndStopListener() returns error? {
check httpListener.detach(serviceObj);
check httpListener.gracefulStop();
runtime:deregisterListener(httpListener);
}
function init() returns error? {
_ = start infiniteLoop();
// add the below code to handle the listener dynamically by the developer
runtime:onGracefulStop(detachAndStopListener);
check httpListener.attach(serviceObj);
check httpListener.'start();
// need to register the listener with the module to activate the listening phase
runtime:registerListener(httpListener);
}
public isolated function infiniteLoop() {
while true {
runtime:sleep(1);
}
}
public function intAdd(int a, int b) returns (int) {
return a + b;
} Call the import ballerina/test;
@test:Config {}
function intAddTest() {
test:assertEquals(intAdd(1, 3), 4);
}
@test:AfterSuite {}
function stopListener() returns error? {
check detachAndStopListener();
} Now since we are deregistering the listener and stopping it by ourselves, it does not hang. |
|
This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now. |
Description
$title
Steps to Reproduce
Create a Ballerina package and add the following code to a module (e.g. default module).
and add the following Ballerina test (or another Ballerina test) in the
tests
folder.Running
bal test
hangs giving the below output.Affected Version(s)
2201.7.0
OS, DB, other environment details and versions
No response
Related area
-> Runtime
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
The text was updated successfully, but these errors were encountered: