Skip to content

race to complete data write #52

@glycerine

Description

@glycerine

It appears that store.Persist() (and store.Close() ) return before persistence to disk is actually completed.

This creates a race and causes a simple write-then-read test (https://github.com/glycerine/bulletin/blob/master/bulletin_test.go#L10) to fail, unless a print is inserted to slow down the test code.

to reproduce: clone https://github.com/glycerine/bulletin and run go test -v


go test -v 
=== RUN   Test001BulletinPersistanceToDisk

  read/write to persistent disk should work ✘


Failures:

  * /Users/jaten/go/src/github.com/glycerine/bulletin/bulletin_test.go
  Line 39:
  Expected: '[]byte{0x61, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65}'
  Actual:   '[]byte(nil)'
  (Should resemble)!


1 assertion thus far

--- FAIL: Test001BulletinPersistanceToDisk (0.00s)
FAIL
exit status 1
FAIL    github.com/glycerine/bulletin   0.014s

commenting in the line https://github.com/glycerine/bulletin/blob/master/bulletin.go#L58 slows down the test, causing it to succeed on my mac book. Hence the code is timing finicky. It should not be. I expected that once Persist() or Close() completed, the data is safely on disk. However, inspection of disk reveals no files written before process shutdown. Hence there is background async processing going on that should be synchronous with the completion of Persiste() and/or Close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions