0

I am using rethinkdb and I am trying to delete all records in a table. The query works without problems when using the Run on the query , thus synchronously. When using the RunAsync the program exits with status code -1.

The program does not throw any exception so how am I supposed to find out why it exists?

public class ChangeFeedTests
{
    [TestCase()]
    public async Task ChangeFeedTest()
    {
       RethinkDB r = RethinkDB.R;  
       Connection.Builder builder = r.Connection();
       builder.Port(Constants.PORT).Hostname(Constants.HOST_NAME);
       Connection con = await builder.ConnectAsync(); /

           try
           {
               var c = await ret.Db(Constants.DB_NAME)
                                .Table(Constants.TABLE_NAME)
                                .Delete().RunAsync(conn); //->exits
                 //------------------.Run(conn)  -> works fine

           }
           catch (Exception ex)
           {

               throw;
           }



        Assert.IsTrue(true);

    }
}
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152

1 Answers1

0

You could have called kept the test async all the way through.

By using the Action you have an async void which wont allow you to catch any of the exceptions.

[TestCase()]
public async Task ChangeFeedTest() {
    //Arrange
    RethinkDB rethinkDb = RethinkDB.R;
    Connection connection = await rethinkDb.Connection()
        .Port(Constants.PORT)
        .Hostname(Constants.HOST_NAME)
        .ConnectAsync();

    //Act
    var actual = await rethinkDb.Db(Constants.DB_NAME).Table(Constants.TABLE_NAME)
                        .Delete().RunAsync(connection);

    //Assert

    //...do assertions here
}

So now any exception thrown would be caught by the test runner and displayed in the test results.

Reference Async/Await - Best Practices in Asynchronous Programming

Nkosi
  • 235,767
  • 35
  • 427
  • 472