The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

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.