bobgus (17) [Avatar] Offline
#1
At the bottom of Listing 7.17 - tests/database_test.nim, the indexes on the messages retrieved need to be changed 0->1 and 1->0 because the messages are retrieved in time order. Since the first message is delayed 4 seconds and the second message only 2 seconds, the first message will appear last (index 1) and the second message will appear first (index 0).

Making the index switches in the Assert statements allows the "All tests finished successfully!" to show.
zolern (6) [Avatar] Offline
#2
Indexes are correct, actually test fails (and error is asserted) because seconds have to be subtracted from, not to be added to getTime(). Opposite means that we post messages from the future smilie

Correct code for posting messages should be:

...
  db.post(Message(
    username: "nim_lang", 
    time: getTime() - 4.seconds,
    msg: "Hello Nim in Action readers"))

  db.post(Message(
    username: "nim_lang", 
    time: getTime() - 2.seconds,
    msg: "99.9% off Nim in Action for everyone, for the next minute only!"))
...
dom96 (75) [Avatar] Offline
#3
Thanks guys, will look into this.