Skip to content
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

Catch2 test results in SIGABRT #87

Closed
vinkaga opened this issue Jun 20, 2019 · 9 comments
Closed

Catch2 test results in SIGABRT #87

vinkaga opened this issue Jun 20, 2019 · 9 comments
Assignees
Labels
Help Wanted Extra attention is needed Question Further information is requested

Comments

@vinkaga
Copy link

vinkaga commented Jun 20, 2019

I created a simple oatpp controller test using catch2 at https://github.com/vinkaga/oatpp-test. I get the following when I run the test (on x86_64 Mac OS X)

$ ./oatpp_test_test
libc++abi.dylib: terminating

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oatpp_test_test is a Catch v2.9.1 host application.
Run with -? for options

-------------------------------------------------------------------------------
Index returns 200
-------------------------------------------------------------------------------
~/dev/oatpp-test/test/ControllerTest.cpp:10
...............................................................................

~/dev/oatpp-test/test/ControllerTest.cpp:10: FAILED:
due to a fatal error condition:
  SIGABRT - Abort (abnormal termination) signal

===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed

Not sure what I am doing wrong, would appreciate any guidance.

@lganzzzo lganzzzo self-assigned this Jun 20, 2019
@lganzzzo lganzzzo added the Help Wanted Extra attention is needed label Jun 20, 2019
@lganzzzo
Copy link
Member

Hello @vinkaga ,

Please find the PR vinkaga/oatpp-test#1

I added some comments to the steps of the test and its structure in the code.

The main problem was that config components were deleted before Runner object tried to inject them.


Apart from that you may find some additional "complicated" code for proper server stoppage and stoppage of async executor. Most of this complexity is because of the "real" port usage and difference in behavior of Linux/BSD api calls, read/write/close.

Which you may avoid by using oatpp virtual networking for test purposes.

You may also find some useful info here Testing oatpp applications


Note

You are using oatpp Async API for you controller. Developing using Async API may be pretty complicated when it comes to business logic / consuming other services / synchronization.

TIP: You may opt to use oatpp simple API (with multi threaded server) instead, which is much more "user friendly".

Async API - is needed for cases where you have to handle more than 1K simultaneous connections.
If you don't expect such load on you service - Simple API is the choice


Please let me know in case of any questions.

Best Regards,
Leonid

@lganzzzo
Copy link
Member

Closing this.
@vinkaga please let me know if there are still questions left.

@lganzzzo lganzzzo added the Question Further information is requested label Jun 21, 2019
@vinkaga
Copy link
Author

vinkaga commented Jun 23, 2019

I switched to using sync API. In order to remove boilerplate from the tests, I modified TestRunner and ControllerTest.

Is this a reasonable approach?

@lganzzzo
Copy link
Member

Hello @vinkaga ,

I have reviewed the code. Looks good to me.

Comments:

Other from that looks great, even that you have defined your own TestRunner. But why not.

Regards,
Leonid

@vinkaga
Copy link
Author

vinkaga commented Jun 25, 2019

Hello Leonid,

Would take a minute to look over the latest iteration of the my oatpp sample/test at https://github.com/vinkaga/oatpp-test? Here is the list of changes since the last version:

  1. Removed Environment usage and moved components into Server and TestClient objects. For me, it's easier for conceptual visualization and also reduces test boilerplate but does reduce dependency injectability.
  2. Added static content handler from your media example.

Additionally, not sure why, I get server running/stopped message twice when I run the test.

$ ./oatppex_test

 Server Running on port 8000

 Server Stopped

 Server Running on port 8000

 Server Stopped
===============================================================================
All tests passed (4 assertions in 2 test cases)

Thanks,
Vinay

@vinkaga
Copy link
Author

vinkaga commented Jun 25, 2019

Ignore my silly concern about 2 runs - 2 tests, 2 runs! :-)

@lganzzzo
Copy link
Member

Hello @vinkaga ,

Would take a minute to look over the latest iteration of the my oatpp sample/test

Currently I am not able to review your code. But I will do it for sure.
Most probably I will be available tomorrow or the day after tomorrow.

Please feel free to put all the questions you have in the issues,- I will answer them all once I am available.

Regards,
Leonid

@lganzzzo
Copy link
Member

Hello @vinkaga ,

I have reviewed the code. Everything looks good!

Some comments:

  • Please move to oatpp version 0.19.6. Project is in alpha so its important to be on a latest version.
  • It is recommended to use oatpp::base::Environment at least in order to make calls to OATPP_LOGD D/V/I/W/E to work and see oatpp system logs. You may also benefit from oatpp object counting in the tests to detect memory-leaks.
  • As you are building static server, you may want to think of a caching mechanism in order to reduce load on a hard-drive.

Regards,
Leonid

@vinkaga
Copy link
Author

vinkaga commented Jun 26, 2019

Leonid,

Thanks again for the feedback.

  • I have updated to 0.19.6 and started using oatpp::base::Environment for logging.
  • I think using std::shared_ptr should prevent any memory leaks.
  • Will definitely consider caching it the load requires it.

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted Extra attention is needed Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants