ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.66k stars 751 forks source link

BallerinaTestException: failed to load Test init class introduced in 2201.1.0 #36585

Closed janihur closed 2 years ago

janihur commented 2 years ago

Description: When I upgraded from 2201.0.3 to 2201.1.0 the unit tests of the following public demonstration project:

https://github.com/janihur/bal-jokes-api/releases/tag/REVIEW_20220617

fails unexpectedly with Ballerina exception:

    jokes.common
Exception in thread "main" org.ballerinalang.test.runtime.exceptions.BallerinaTestException: failed to load Test init class :jani.jokes$0046common$test.0.jokes$$$common
    at org.ballerinalang.test.runtime.Main.replaceMockedFunctions(Main.java:193)
    at org.ballerinalang.test.runtime.Main.main(Main.java:116)
error: there are test failures

Steps to reproduce:

2201.0.3 works:

$ bal dist use 2201.0.3
'2201.0.3' successfully set as the active distribution
$ bal test
Compiling source
    jani/jokes:0.1.0

Running Tests

    jokes.chucknorris
time = 2022-06-17T11:20:52.472+03:00 level = ERROR module = jani/jokes.chucknorris message = "CHUCKNORRIS http:ClientError" error = "HTTP_CLIENT_ERROR"
time = 2022-06-17T11:20:52.654+03:00 level = INFO module = jani/jokes.chucknorris message = "CHUCKNORRIS http:Response" statusCode = 200 reasonPhase = "" contentType = "" resolvedRequestedURI = "" server = "" entity.ContentType = "" entity.body = "error ParserError (\"Error occurred while extracting text data from entity\",error(\"String payload is null\"))"
time = 2022-06-17T11:20:52.731+03:00 level = ERROR module = jani/jokes.chucknorris message = "CHUCKNORRIS http:Response" statusCode = 404 reasonPhase = "" contentType = "application/json" resolvedRequestedURI = "" server = "" entity.ContentType = "application/json" header.content-type = "application/json" entity.body = "{\"timestamp\":\"2022-06-12T09:26:21.294Z\",\"status\":404,\"error\":\"Not Found\",\"message\":\"Joke with id \"randomxxx\" not found.\",\"path\":\"/jokes/randomxxx\"}"
time = 2022-06-17T11:20:52.771+03:00 level = INFO module = jani/jokes.chucknorris message = "CHUCKNORRIS http:Response" statusCode = 200 reasonPhase = "" contentType = "application/json" resolvedRequestedURI = "" server = "" entity.ContentType = "application/json" header.content-type = "application/json" entity.body = "{\"categories\":[],\"created_at\":\"2020-01-05 13:42:20.568859\",\"icon_url\":\"https://assets.chucknorris.host/img/avatar/chuck-norris.png\",\"id\":\"CARdiEISR9CaJa5CAIxy7g\",\"updated_at\":\"2020-01-05 13:42:20.568859\",\"url\":\"https://api.chucknorris.io/jokes/CARdiEISR9CaJa5CAIxy7g\",\"value\":\"they say Santa comes once a yer Chuck Norris comes twice a year\"}"

        4 passing
        0 failing
        0 skipped

    jokes.common

        3 passing
        0 failing
        0 skipped

    jokes
ballerina: HTTP access log enabled
time = 2022-06-17T11:20:53.810+03:00 level = INFO module = jani/jokes message = "json2 (GET)" family = "simpsons" amount = 
time = 2022-06-17T11:20:53.813+03:00 level = INFO module = jani/jokes message = "json2 (GET)" response = "{\"status\":object http:StatusOK,\"body\":{\"jokes\":[{\"family\":\"simpsons\",\"text\":\"Eat my shorts\"}]}}"
127.0.0.1 - - [17/Jun/2022:11:20:53 +0300] "GET /jokes/v1/json?family=simpsons HTTP/1.1" 200 57 "-" "ballerina" 
time = 2022-06-17T11:20:53.998+03:00 level = INFO module = jani/jokes message = "json2 (GET)" family = "simpsons" amount = 
time = 2022-06-17T11:20:54.005+03:00 level = INFO module = jani/jokes message = "json2 (GET)" response = "{\"status\":object http:StatusInternalServerError,\"body\":{\"code\":\"IMPLEMENTATION\",\"details\":\"{ballerina}DivisionByZero\"}}"
127.0.0.1 - - [17/Jun/2022:11:20:53 +0300] "GET /jokes/v1/json?family=simpsons HTTP/1.1" 500 64 "-" "ballerina" 

        9 passing
        0 failing
        0 skipped

    jokes.simpsons
time = 2022-06-17T11:20:54.296+03:00 level = ERROR module = jani/jokes.simpsons message = "SIMPSONS http:ClientError" error = "HTTP_CLIENT_ERROR"
time = 2022-06-17T11:20:54.318+03:00 level = INFO module = jani/jokes.simpsons message = "SIMPSONS http:Response" statusCode = 200 reasonPhase = "" contentType = "" resolvedRequestedURI = "" server = "" entity.ContentType = "" entity.body = "error ParserError (\"Error occurred while extracting text data from entity\",error(\"String payload is null\"))"
time = 2022-06-17T11:20:54.324+03:00 level = ERROR module = jani/jokes.simpsons message = "SIMPSONS http:ClientError" error = "No content"
time = 2022-06-17T11:20:54.386+03:00 level = ERROR module = jani/jokes.simpsons message = "SIMPSONS http:Response" statusCode = 404 reasonPhase = "" contentType = "text/html;charset=utf-8" resolvedRequestedURI = "" server = "" entity.ContentType = "text/html;charset=utf-8" header.content-type = "text/html;charset=utf-8" entity.body = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot GET /quotesxxx</pre>\n</body>\n</html>"
time = 2022-06-17T11:20:54.404+03:00 level = INFO module = jani/jokes.simpsons message = "SIMPSONS http:Response" statusCode = 200 reasonPhase = "" contentType = "application/json" resolvedRequestedURI = "" server = "" entity.ContentType = "application/json" header.content-type = "application/json" entity.body = "[{\"quote\":\"Eat my shorts\",\"character\":\"Bart Simpson\",\"image\":\"https://cdn.glitch.com/3c3ffadc-3406-4440-bb95-d40ec8fcde72%2FBartSimpson.png?1497567511638\",\"characterDirection\":\"Right\"}]"

        4 passing
        0 failing
        0 skipped

but 2201.1.0 fails:

$ bal dist use 2201.1.0
'2201.1.0' successfully set as the active distribution

$ bal test
Compiling source
    jani/jokes:0.1.0
ballerina/url:2.2.1 [central.ballerina.io -> home repo]  100% [==========] 15/15 KB (0:00:00 
    ballerina/url:2.2.1 pulled from central successfully
ballerina/cache:3.2.1 [central.ballerina.io -> home repo]  100% [==========] 37/37 KB (0:00:0
    ballerina/cache:3.2.1 pulled from central successfully
ballerina/task:2.2.1 [central.ballerina.io -> home repo]  100% [==========] 736/736 KB (0:00:
    ballerina/task:2.2.1 pulled from central successfully
ballerina/io:1.2.1 [central.ballerina.io -> home repo]  100% [==========] 115/115 KB (0:00:00
    ballerina/io:1.2.1 pulled from central successfully
ballerina/crypto:2.2.1 [central.ballerina.io -> home repo]  100% [==========] 6293/6293 KB (0
    ballerina/crypto:2.2.1 pulled from central successfully
ballerina/xmldata:2.2.1 [central.ballerina.io -> home repo]  100% [==========] 22/22 KB (0:00
    ballerina/xmldata:2.2.1 pulled from central successfully
ballerina/time:2.2.1 [central.ballerina.io -> home repo]  100% [==========] 36/36 KB (0:00:00
    ballerina/time:2.2.1 pulled from central successfully
WARNING [Ballerina.toml:(1:1,2:26)] missing key 'name' in table '[package]' in 'Ballerina.toml'. Defaulting to 'name = "jokes"'
WARNING [Ballerina.toml:(1:1,2:26)] missing key 'org' in table '[package]' in 'Ballerina.toml'. Defaulting to 'org = "jani"'
WARNING [Ballerina.toml:(1:1,2:26)] missing key 'version' in table '[package]' in 'Ballerina.toml'. Defaulting to 'version = "0.1.0"'

Running Tests

    jokes.chucknorris
time = 2022-06-17T11:21:32.869+03:00 level = ERROR module = jani/jokes.chucknorris message = "CHUCKNORRIS http:ClientError" error = "HTTP_CLIENT_ERROR"
time = 2022-06-17T11:21:33.104+03:00 level = INFO module = jani/jokes.chucknorris message = "CHUCKNORRIS http:Response" statusCode = 200 reasonPhase = "" contentType = "" resolvedRequestedURI = "" server = "" entity.ContentType = "" entity.body = "error ParserError (\"Error occurred while extracting text data from entity\",error NoContentError (\"String payload is null\"))"
time = 2022-06-17T11:21:33.151+03:00 level = ERROR module = jani/jokes.chucknorris message = "CHUCKNORRIS http:Response" statusCode = 404 reasonPhase = "" contentType = "application/json" resolvedRequestedURI = "" server = "" entity.ContentType = "application/json" header.content-type = "application/json" entity.body = "{\"timestamp\":\"2022-06-12T09:26:21.294Z\",\"status\":404,\"error\":\"Not Found\",\"message\":\"Joke with id \"randomxxx\" not found.\",\"path\":\"/jokes/randomxxx\"}"
time = 2022-06-17T11:21:33.200+03:00 level = INFO module = jani/jokes.chucknorris message = "CHUCKNORRIS http:Response" statusCode = 200 reasonPhase = "" contentType = "application/json" resolvedRequestedURI = "" server = "" entity.ContentType = "application/json" header.content-type = "application/json" entity.body = "{\"categories\":[],\"created_at\":\"2020-01-05 13:42:20.568859\",\"icon_url\":\"https://assets.chucknorris.host/img/avatar/chuck-norris.png\",\"id\":\"CARdiEISR9CaJa5CAIxy7g\",\"updated_at\":\"2020-01-05 13:42:20.568859\",\"url\":\"https://api.chucknorris.io/jokes/CARdiEISR9CaJa5CAIxy7g\",\"value\":\"they say Santa comes once a yer Chuck Norris comes twice a year\"}"

        4 passing
        0 failing
        0 skipped

    jokes.common
Exception in thread "main" org.ballerinalang.test.runtime.exceptions.BallerinaTestException: failed to load Test init class :jani.jokes$0046common$test.0.jokes$$$common
    at org.ballerinalang.test.runtime.Main.replaceMockedFunctions(Main.java:193)
    at org.ballerinalang.test.runtime.Main.main(Main.java:116)
error: there are test failures
$ 
janihur commented 2 years ago

If I remove the offending test file jokes/modules/common/test/common_test.bal I'll get the following problem:

    jokes
ballerina: HTTP access log enabled
error: Dependant module initialization for test suite failed due to java.lang.ClassFormatError: Truncated class file
    at java.lang.ClassLoader:defineClass1(ClassLoader.java:-2)
      java.lang.ClassLoader:defineClass(ClassLoader.java:1017)
      java.lang.ClassLoader:defineClass(ClassLoader.java:878)
      org.ballerinalang.test.runtime.CustomClassLoader:findClass(CustomClassLoader.java:47)
      java.lang.ClassLoader:loadClass(ClassLoader.java:589)
      java.lang.ClassLoader:loadClass(ClassLoader.java:522)
      jani:.<init>(jokes.chucknorris:1)
      jani:$moduleInit(jokes:-1)
      jdk.internal.reflect.NativeMethodAccessorImpl:invoke0(NativeMethodAccessorImpl.java:-2)
      jdk.internal.reflect.NativeMethodAccessorImpl:invoke(NativeMethodAccessorImpl.java:62)
      jdk.internal.reflect.DelegatingMethodAccessorImpl:invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method:invoke(Method.java:566)
      org.ballerinalang.test.runtime.entity.TesterinaFunction:lambda$runOnSchedule$0(TesterinaFunction.java:108)
      io.ballerina.runtime.internal.scheduling.SchedulerItem:execute(Scheduler.java:610)
      io.ballerina.runtime.internal.scheduling.Scheduler:run(Scheduler.java:316)
      io.ballerina.runtime.internal.scheduling.Scheduler:runSafely(Scheduler.java:283)
      java.lang.Thread:run(Thread.java:834)

This time all the other tests run fine.

github-actions[bot] commented 2 years ago

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.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.