Skip to content

Commit

Permalink
Add tests for async send action
Browse files Browse the repository at this point in the history
  • Loading branch information
prakanth97 committed Jun 20, 2023
1 parent 4cef482 commit 00909f2
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BMap;
import org.ballerinalang.test.BAssertUtil;
import org.ballerinalang.test.BCompileUtil;
import org.ballerinalang.test.BRunUtil;
import org.ballerinalang.test.CompileResult;
Expand Down Expand Up @@ -143,10 +144,28 @@ public void testAsyncSendAsExpression(String funcName) {
public Object[] asyncSendAsExpressionFunctions() {
return new Object[]{
"testAsyncSendAsExpressionReturnType",
"testAsyncSendAsExpressionWithPanic"
"testAsyncSendAsExpressionWithPanic",
"testAsyncSendAsExpressionWithTrapAndCheckExpr",
"testAsyncSendAsExpressionWithTypeCastExpr",
"testAsyncSendAsExpressionWithReturnStmt",
"testAsyncSendAsExpressionWithWildCardBindingPattern",
"testAsyncSendAsExpressionWithMatchStmt"
};
}

@Test
public void testAsyncSendNegative() {
CompileResult asyncSendNegativeResult =
BCompileUtil.compile("test-src/workers/worker_async_send_negative.bal");
int i = 0;
BAssertUtil.validateError(asyncSendNegativeResult, i++, "incompatible types: '()' is not an " +
"iterable collection", 19, 26);
BAssertUtil.validateError(asyncSendNegativeResult, i++, "compound assignment not allowed with " +
"nullable operands", 34, 9);
BAssertUtil.validateError(asyncSendNegativeResult, i++, "operator '+' not defined for 'int' and '()'", 34, 9);
Assert.assertEquals(i, asyncSendNegativeResult.getErrorCount());
}

@AfterClass
public void tearDown() {
result = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com)
//
// WSO2 Inc. licenses this file to you under the Apache License,
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -49,7 +49,91 @@ function testAsyncSendAsExpressionWithPanic() {
x = <- w1;
}

map<error??> mapResult = wait {w1, w2};
map<error?> mapResult = wait {w1, w2};
}

function testAsyncSendAsExpressionWithTrapAndCheckExpr() {
worker w1 {
() a = check (5 -> w2);
assertValueEquality(a, ());
error? b = trap (15 -> w2);
if b is error {
assertValueEquality("This is an error", b.message());
} else {
assertValueEquality(b, ());
}
}

worker w2 returns error? {
int x = <- w1;
if (x == 5) {
return error("This is an error");
}
x = <- w1;
}

map<error?> mapResult = wait {w1, w2};
}

function testAsyncSendAsExpressionWithTypeCastExpr() {
worker w1 {
() a = <()>(5 -> w2);
assertValueEquality((), a);
}

worker w2 {
int x = <- w1;
assertValueEquality(5, x);
}

_ = wait {w1, w2};
}

function testAsyncSendAsExpressionWithReturnStmt() {
worker w1 {
return (5 -> w2);
}

worker w2 {
int x = <- w1;
assertValueEquality(5, x);
}

_ = wait {w1, w2};
}

function testAsyncSendAsExpressionWithWildCardBindingPattern() {
worker w1 {
_ = 5 -> w2;
}

worker w2 {
int x = <- w1;
assertValueEquality(5, x);
}

_ = wait {w1, w2};
}

function testAsyncSendAsExpressionWithMatchStmt() {
worker w1 {
match (5 -> w2) {
() => {
return;
}

_ => {
panic error("This is an error");
}
}
}

worker w2 {
int x = <- w1;
assertValueEquality(5, x);
}

_ = wait {w1, w2};
}

type AssertionError distinct error;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com)
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

function testAsyncSendAsExpressionWithForEachStmt() {
worker w1 {
foreach var j in 5 -> w2 {

}
}

worker w2 {
int x = <- w1;
}

_ = wait {w1, w2};
}

function testAsyncSendAsExpressionWithCompoundAssignmentStmt() {
worker w1 {
int result = 4;
result += 5 -> w2;
}

worker w2 {
int x = <- w1;
}

_ = wait {w1, w2};
}

0 comments on commit 00909f2

Please sign in to comment.