         test.isTrue res
 
     # Sleep so that observers have time to update documents
-    pollUntil expect, ->
-      false
-    , 500, 100, true
+    Meteor.setTimeout expect(), 500
 ,
   (test, expect) ->
     @circularFirst = CircularFirsts.findOne @circularFirstId,

  # Invalid document should not be added to the list
  test.equal Document.Meta.list, [UserLink, CircularSecond, Person, CircularFirst, Recursive, Post]

testAsyncMulti 'meteor-peerdb - delayed defintion', [
  (test, expect) ->
    class BadPost extends Document
      @Meta =>
        collection: Posts
        fields:
          author: @Reference undefined, ['username']

    Log._intercept 2 # Two to see if we catch more than expected

    # Sleep so that error is shown
    pollUntil expect, ->
      false
    , 1100, 100, true
,
  (test, expect) ->
    intercepted = Log._intercepted()

    test.equal intercepted.length, 1, intercepted

    intercepted = EJSON.parse intercepted[0]

    test.equal intercepted.message, "Not all delayed document definitions were successfully retried: BadPost"
    test.equal intercepted.level, 'error'

    test.equal Document.Meta.list, [UserLink, CircularSecond, Person, CircularFirst, Recursive, Post]
    test.equal Document.Meta.delayed.length, 1

    # Clear delayed so that we can retry tests without errors
    Document.Meta.delayed = []
]

testAsyncMulti 'meteor-peerdb - circular changes', [
  (test, expect) ->
    Log._intercept 3 if Meteor.isServer # Three to see if we catch more than expected

        test.isTrue res

    # Sleep so that observers have time to update documents
    Meteor.setTimeout expect(), 500
,
  (test, expect) ->
    @circularFirst = CircularFirsts.findOne @circularFirstId,
