scala - Why does this Slick test inconsistently fail? -


i coding simple getting started (http://slick.typesafe.com/doc/3.1.1/gettingstarted.html) examples slick 3.1.1 documentation.

i wrote following test assert on count of coffees:

@test def countcoffees() = {      // read coffees , print them console     val rf = db.run(coffees.result)     // equivalent sql code:     // select cof_name, sup_id, price, sales, total coffees      val r = await.result(rf, duration.inf)      assert(r.size == 5)   } 

some times test pass , other times result following:

[info] - countcoffees *** failed *** [info]   org.scalatest.junit.junittestfailederror: vector() had size 0 instead of expected size 5 (test.scala:40) 

the testsuite defined follows:

class slickscalaejemplo extends funsuite schemaejemplo 

being schemaejemplo follows

trait schemaejemplo extends funsuite slickbase beforeandafter {    val setup = dbio.seq(     // create tables, including primary , foreign keys     (suppliers.schema ++ coffees.schema).create,      // insert suppliers     suppliers += (101, "acme, inc.", "99 market street", "groundsville", "ca", "95199"),     suppliers += (49, "superior coffee", "1 party place", "mendocino", "ca", "95460"),     suppliers += (150, "the high ground", "100 coffee lane", "meadows", "ca", "93966"),     // equivalent sql code:     // insert suppliers(sup_id, sup_name, street, city, state, zip) values (?,?,?,?,?,?)      // insert coffees (using jdbc's batch insert feature, if supported db)     coffees ++= seq(       ("colombian", 101, 7.99, 0, 0),       ("french_roast", 49, 8.99, 0, 0),       ("espresso", 150, 9.99, 0, 0),       ("colombian_decaf", 101, 8.99, 0, 0),       ("french_roast_decaf", 49, 9.99, 0, 0)     )   // equivalent sql code:   // insert coffees(cof_name, sup_id, price, sales, total) values (?,?,?,?,?)   )    val setupfuture = db.run(setup)    after {     db.close()   }  } 

why await on test don't work properly?

the problem was not waiting following

val setupfuture = db.run(setup) 

to execute tests running without expecting schema created or completed.

i changed tests follows:

  test("countcoffees") {      setupfuture.map(x => {       // read coffees , print them console       val rf = db.run(coffees.result)       // equivalent sql code:       // select cof_name, sup_id, price, sales, total coffees        val r = await.result(rf, duration.inf)        assert(r.size == 5)     })    } 

so execution of different action db.run executed on complete schema , tests green.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -