problems with testing an implementation of AuthProvider

79 views
Skip to first unread message

Michael Remme

unread,
Mar 10, 2015, 12:30:27 PM3/10/15
to ve...@googlegroups.com
Hey,

i implemented a MongoAuthProvider in a first version. By starting to write the test units i'm faced with a strange problem. 
When i am running the test normal, i am getting an error from out of 
  io.vertx.ext.auth.impl.AuthServiceImpl.loginWithTimeout(JsonObject, long, Handler<AsyncResult<String>>)
 line 67: resultHandler.handle(Future.failedFuture("null principal"));

When i am debugging that, everything is fine and the test finishes positiv.
When i am setting a breakpoint onto the line 67, i can see, that the result should be positive, cause there is existing a principal inside the res.

Thus i guess i made some mistakes here, because i'm not yet used to the principals of vertx.
Could somebody check that and give me a hint, please?


Start the test io.vertx.ext.auth.mongo.MongoAuthTest

tia, Mike

Tim Fox

unread,
Mar 11, 2015, 6:14:13 AM3/11/15
to ve...@googlegroups.com
Mike,

Do you have a link to your test and some instructions on how to
reproduce this?

Michael Remme

unread,
Mar 11, 2015, 8:39:19 AM3/11/15
to ve...@googlegroups.com
The project is here:

The test class is 

Just start the test class with junit. This should produce an error "null principal" from out of your AuthServiceImpl.loginWithTimeout.
When i let that run with a breakpoint, then everything is fine. 

I guess this is, cause i am not yet used enough to asynchronous and that my little brain created a violation. 

I think the origin of the error is in https://github.com/remi128/apex-test/blob/master/src/main/java/io/vertx/ext/auth/mongo/MongoAuthProvider.java line 325. There i am starting the request by overpasssing a handler, but do not wait, until the handler is called. And in fact in vertx i don't know how to wait without blocking.


Michael Remme

unread,
Mar 11, 2015, 8:50:06 AM3/11/15
to ve...@googlegroups.com
i think i got it

i am overpassing the external resulthandler onto the handler for MongoService and it seems to work

Tim Fox

unread,
Mar 13, 2015, 7:41:02 AM3/13/15
to ve...@googlegroups.com
The problem is that your method "initOneUser" calls mongo to save some
data but your code does not wait for the save to complete before your
test is run.

This means there is no guarantee that the user is inserted by the time
the main part of your test is run.

I recommend you use vertx-unit for asynchronous testing as it has good
support for async setup tasks.

On 10/03/15 16:30, Michael Remme wrote:
Reply all
Reply to author
Forward
0 new messages