예제 #1
0
 def test_sets_last_seq(self):
     docs = [{'doc': {'name': 'foo', 'description': 'Foo.'}}] * 13
     assert self.db.one(
         'select npm_last_seq from worker_coordination') == -1
     sync_npm.consume_change_stream(self.change_stream(docs), self.db)
     assert self.db.one(
         'select npm_last_seq from worker_coordination') == 12
예제 #2
0
 def test_not_afraid_to_delete_docs(self):
     docs = [ {'doc': {'name': 'foo', 'description': 'Foo.'}}
            , {'doc': {'name': 'foo', 'description': 'Foo?'}}
            , {'deleted': True, 'id': 'foo'}
             ]
     sync_npm.consume_change_stream(self.change_stream(docs), self.db)
     assert self.db.one('select * from packages') is None
예제 #3
0
def main():
    """This function is installed via an entrypoint in ``setup.py`` as
    ``sync-npm``.

    Usage::

      sync-npm

    """
    env = wireup.env()
    db = wireup.db(env)
    while 1:
        with sentry.teller(env):
            last_seq = get_last_seq(db)
            log("Picking up with npm sync at {}.".format(last_seq))
            stream = production_change_stream(last_seq)
            consume_change_stream(stream, db)
        try:
            last_seq = get_last_seq(db)
            sleep_for = 60
            log('Encountered an error, will pick up with %s in %s seconds (Ctrl-C to exit) ...'
                % (last_seq, sleep_for))
            time.sleep(sleep_for)  # avoid a busy loop if thrashing
        except KeyboardInterrupt:
            return
예제 #4
0
 def test_consumes_change_stream_with_missing_doc(self):
     docs = [ {'doc': {'name': 'foo', 'description': 'Foo.'}}
            , {'doc': {'name': 'foo', 'description': 'Foo?'}}
            , {'': {'name': 'foo', 'description': 'Foo!'}}
             ]
     sync_npm.consume_change_stream(self.change_stream(docs), self.db)
     package = self.db.one('select * from packages')
     assert package.package_manager == 'npm'
     assert package.name == 'foo'
     assert package.description == 'Foo?'
     assert package.emails == []
예제 #5
0
    def test_even_deletes_package_with_linked_team(self):

        # Set up package linked to team.
        foo = self.make_package()
        alice = self.make_participant('alice')
        with self.db.get_cursor() as cursor:
            team = foo.get_or_create_linked_team(cursor, alice)
        assert self.db.one('select p.*::packages from packages p').team == team

        # Delete package.
        docs = [{'deleted': True, 'id': 'foo'}]
        sync_npm.consume_change_stream(self.change_stream(docs), self.db)
        assert self.db.one('select * from packages') is None
예제 #6
0
    def test_even_deletes_package_with_linked_team(self):

        # Set up package linked to team.
        foo = self.make_package()
        alice = self.make_participant('alice')
        with self.db.get_cursor() as cursor:
            team = foo.get_or_create_linked_team(cursor, alice)
        assert self.db.one('select p.*::packages from packages p').team == team

        # Delete package.
        docs = [{'deleted': True, 'id': 'foo'}]
        sync_npm.consume_change_stream(self.change_stream(docs), self.db)
        assert self.db.one('select * from packages') is None
예제 #7
0
 def test_not_afraid_to_delete_docs(self):
     docs = [{
         'doc': {
             'name': 'foo',
             'description': 'Foo.'
         }
     }, {
         'doc': {
             'name': 'foo',
             'description': 'Foo?'
         }
     }, {
         'deleted': True,
         'id': 'foo'
     }]
     sync_npm.consume_change_stream(self.change_stream(docs), self.db)
     assert self.db.one('select * from packages') is None
예제 #8
0
 def test_consumes_change_stream_with_missing_doc(self):
     docs = [{
         'doc': {
             'name': 'foo',
             'description': 'Foo.'
         }
     }, {
         'doc': {
             'name': 'foo',
             'description': 'Foo?'
         }
     }, {
         '': {
             'name': 'foo',
             'description': 'Foo!'
         }
     }]
     sync_npm.consume_change_stream(self.change_stream(docs), self.db)
     package = self.db.one('select * from packages')
     assert package.package_manager == 'npm'
     assert package.name == 'foo'
     assert package.description == 'Foo?'
     assert package.emails == []
예제 #9
0
 def test_delete_tolerates_inexistent_packages(self):
     docs = [{'deleted': True, 'id': 'foo'}]
     sync_npm.consume_change_stream(self.change_stream(docs), self.db)
예제 #10
0
 def test_sets_last_seq(self):
     docs = [{'doc': {'name': 'foo', 'description': 'Foo.'}}] * 13
     assert self.db.one('select npm_last_seq from worker_coordination') == -1
     sync_npm.consume_change_stream(self.change_stream(docs), self.db)
     assert self.db.one('select npm_last_seq from worker_coordination') == 12
예제 #11
0
 def test_delete_tolerates_inexistent_packages(self):
     docs = [{'deleted': True, 'id': 'foo'}]
     sync_npm.consume_change_stream(self.change_stream(docs), self.db)