Skip to content

Commit

Permalink
Add tests for async send action as expression
Browse files Browse the repository at this point in the history
  • Loading branch information
prakanth97 committed Oct 18, 2022
1 parent bebc91b commit d558080
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class BasicWorkerActionsNegativeTest {
public void testWorkerActionsSemanticsNegative() {
int index = 0;
CompileResult resultSemanticsNegative = BCompileUtil.compile("test-src/workers/actions-semantics-negative.bal");
Assert.assertEquals(resultSemanticsNegative.getErrorCount(), 10, "Worker actions semantics negative test error" +
" count");
Assert.assertEquals(resultSemanticsNegative.getErrorCount(), 10, "Worker actions semantics negative test " +
"error count");
BAssertUtil.validateError(resultSemanticsNegative, index++,
"invalid type for worker send 'Person', expected value:Cloneable", 42, 9);
BAssertUtil.validateError(resultSemanticsNegative, index++,
Expand Down Expand Up @@ -133,15 +133,4 @@ private String formatMessage(String workerName) {
return String.format(
"multiple references to a named worker '%s' as a variable reference is not allowed", workerName);
}

@Test(enabled = false)
public void testAsyncSendAsExpression() {
// TODO: support async send as expression issue #24849
CompileResult compileResult = BCompileUtil.compile("test-src/workers/worker_async_send_as_expression.bal");
int index = 0;
BAssertUtil.validateError(compileResult, index++, "async send action not yet supported as expression",
19, 16);

Assert.assertEquals(compileResult.getErrorCount(), index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@
public class BasicWorkerTest {

private CompileResult result;
private CompileResult asyncSendResult;

@BeforeClass
public void setup() {
this.result = BCompileUtil.compile("test-src/workers/basic-worker-actions.bal");
Assert.assertEquals(result.getErrorCount(), 0, Arrays.asList(result.getDiagnostics()).toString());

this.asyncSendResult =
BCompileUtil.compile("test-src/workers/worker_async_send_as_expression.bal");
Assert.assertEquals(asyncSendResult.getErrorCount(), 0, Arrays.asList(result.getDiagnostics()).toString());
}

@Test
Expand Down Expand Up @@ -129,6 +134,19 @@ public Object[] workerMessagePassingFunctions() {
};
}

@Test(dataProvider = "asyncSendAsExpressionFunctions")
public void testAsyncSendAsExpression(String funcName) {
BRunUtil.invoke(asyncSendResult, funcName);
}

@DataProvider(name = "asyncSendAsExpressionFunctions")
public Object[] asyncSendAsExpressionFunctions() {
return new Object[]{
"testAsyncSendAsExpressionReturnType",
"testAsyncSendAsExpressionWithPanic"
};
}

@AfterClass
public void tearDown() {
result = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,51 @@
// specific language governing permissions and limitations
// under the License.

function foo() {
function testAsyncSendAsExpressionReturnType() {
worker w1 {
() a = 5 -> w2;
assertValueEquality(a, ());

var b = "Foo" -> w2;
assertValueEquality(b, ());
}

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

string y = <- w1;
assertValueEquality("Foo", y);
}

_ = wait {w1, w2};
}

function testAsyncSendAsExpressionWithPanic() {
worker w1 {
() a = 5 -> w2;
() b = 15 -> w2;
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};
}

type AssertionError distinct error;
const ASSERTION_ERROR_REASON = "AssertionError";

function assertValueEquality(anydata expected, anydata actual) {
if expected == actual {
return;
}
panic error(ASSERTION_ERROR_REASON,
message = "expected '" + expected.toString() + "', found '" + actual.toString () + "'");
}

0 comments on commit d558080

Please sign in to comment.