def setUp(self):
        self.workdir = tempfile.mkdtemp(prefix='repo_poller_simple_test')
        self.repo_src = os.path.join(self.workdir, 'repo-src')
        self.repo_work = os.path.join(self.workdir, 'repo-work')

        manifest_dir = os.path.join(self.repo_src, 'manifest')
        git_dir_base = os.path.join(self.repo_src, 'git')
        git_dirs = ['%s%d' % (git_dir_base, x) for x in range(PROJ_COUNT)]
        git_dirs += [
            os.path.join(self.repo_src, BRANCH_UNIQUE_PROJ_NAME % br)
            for br in REPO_BRANCHES
        ]

        for d in git_dirs + [manifest_dir, self.repo_work]:
            if not os.path.exists(d):
                os.makedirs(d)

        for d in git_dirs + [manifest_dir]:
            self.assertFalse(_cmd(['git', 'init', '--quiet'], d))

        def _masterToFront(x, y):
            return int(y == 'master') - int(x == 'master')

        REPO_BRANCHES.sort(cmp=_masterToFront)

        for n, branch in enumerate(REPO_BRANCHES):
            # when n==0 we're creating master, and 'checkout -b' will fail
            self.assertFalse(
                _cmd(['git', 'checkout', '-q', '-b', branch], manifest_dir)
                and n != 0)
            fh = open(os.path.join(manifest_dir, 'default.xml'), 'w')
            fh.write(
                REPO_MANIFEST % {
                    'branch': branch,
                    'branch-unique-project': BRANCH_UNIQUE_PROJ_NAME % branch
                })
            fh.close()
            self.assertFalse(_cmd(['git', 'add', 'default.xml'], manifest_dir))
            self.assertFalse(
                _cmd(['git', 'commit', '-q', '-m', 'empty'], manifest_dir))
        # repo does something too smart with the commiter's email while switching
        # branches within the manifest project that confuses it. We need to change
        # it here before we try using the project from a repo client, else
        # `repo init` fails
        self.assertFalse(
            _cmd([
                'git', 'filter-branch', '-f', '--env-filter',
                'GIT_COMMITTER_EMAIL=no_one'
            ] + REPO_BRANCHES, manifest_dir))

        for n, branch in enumerate(REPO_BRANCHES):
            for x, git_dir in enumerate(git_dirs):
                # when n==0 we're creating master, and 'checkout -b' will fail
                self.assertFalse(
                    _cmd(['git', 'checkout', '-q', '-b', branch], git_dir)
                    and n != 0)
                fh = open(os.path.join(git_dir, 'file%d.txt' % x), 'w')
                fh.write('Contents of file%d.txt in branch %s\n' % (x, branch))
                fh.close()
                self.assertFalse(
                    _cmd(['git', 'add', 'file%d.txt' % x], git_dir))
                self.assertFalse(
                    _cmd(['git', 'commit', '-q', '-m', 'empty'], git_dir))

        cmd = [
            REPO_BIN, 'init', '--no-repo-verify', '--repo-url', REPO_URL, '-u',
            manifest_dir
        ]
        self.assertFalse(_cmd(cmd, self.repo_work))
        self.poller = RepoPoller(self.repo_src,
                                 repo_branches=REPO_BRANCHES,
                                 workdir=self.repo_work,
                                 pollInterval=999999,
                                 repo_bin=REPO_BIN,
                                 from_addr='*****@*****.**',
                                 to_addrs='*****@*****.**',
                                 smtp_host='nohost')
        self.poller.startService()
Ejemplo n.º 2
0
  def setUp(self):
    self.workdir = tempfile.mkdtemp(prefix='repo_poller_simple_test')
    self.repo_src = os.path.join(self.workdir, 'repo-src')
    self.repo_work = os.path.join(self.workdir, 'repo-work')

    manifest_dir = os.path.join(self.repo_src, 'manifest')
    git_dir_base = os.path.join(self.repo_src, 'git')
    git_dirs = ['%s%d' % (git_dir_base, x) for x in range(PROJ_COUNT)]
    git_dirs += [os.path.join(self.repo_src, BRANCH_UNIQUE_PROJ_NAME % br)
                 for br in REPO_BRANCHES]

    for d in git_dirs + [manifest_dir, self.repo_work]:
      if not os.path.exists(d):
        os.makedirs(d)

    for d in git_dirs + [manifest_dir]:
      self.assertFalse(_cmd(['git', 'init', '--quiet'], d))

    def _masterToFront(x, y): return int(y == 'master') - int(x == 'master')
    REPO_BRANCHES.sort(cmp=_masterToFront)

    for n, branch in enumerate(REPO_BRANCHES):
      # when n==0 we're creating master, and 'checkout -b' will fail
      self.assertFalse(_cmd(['git', 'checkout', '-q', '-b', branch],
                            manifest_dir)
                       and n != 0)
      fh = open(os.path.join(manifest_dir, 'default.xml'), 'w')
      fh.write(REPO_MANIFEST %
               {'branch': branch,
                'branch-unique-project': BRANCH_UNIQUE_PROJ_NAME % branch})
      fh.close()
      self.assertFalse(_cmd(['git', 'add', 'default.xml'], manifest_dir))
      self.assertFalse(_cmd(['git', 'commit', '-q', '-m', 'empty'],
                            manifest_dir))
    # repo does something too smart with the commiter's email while switching
    # branches within the manifest project that confuses it. We need to change
    # it here before we try using the project from a repo client, else
    # `repo init` fails
    self.assertFalse(_cmd(['git', 'filter-branch', '-f', '--env-filter',
                           'GIT_COMMITTER_EMAIL=no_one'] + REPO_BRANCHES,
                          manifest_dir))

    for n, branch in enumerate(REPO_BRANCHES):
      for x, git_dir in enumerate(git_dirs):
        # when n==0 we're creating master, and 'checkout -b' will fail
        self.assertFalse(_cmd(['git', 'checkout', '-q', '-b', branch], git_dir)
                         and n != 0)
        fh = open(os.path.join(git_dir, 'file%d.txt' % x), 'w')
        fh.write('Contents of file%d.txt in branch %s\n' % (x, branch))
        fh.close()
        self.assertFalse(_cmd(['git', 'add', 'file%d.txt' % x], git_dir))
        self.assertFalse(_cmd(['git', 'commit', '-q', '-m', 'empty'], git_dir))


    cmd = [REPO_BIN, 'init', '--no-repo-verify',
           '--repo-url', REPO_URL, '-u', manifest_dir]
    self.assertFalse(_cmd(cmd, self.repo_work))
    self.poller = RepoPoller(self.repo_src, repo_branches=REPO_BRANCHES,
                             workdir=self.repo_work, pollInterval=999999,
                             repo_bin=REPO_BIN, from_addr='*****@*****.**',
                             to_addrs='*****@*****.**',
                             smtp_host='nohost')
    self.poller.startService()
class TestRepoPoller(unittest.TestCase):
    def setUp(self):
        self.workdir = tempfile.mkdtemp(prefix='repo_poller_simple_test')
        self.repo_src = os.path.join(self.workdir, 'repo-src')
        self.repo_work = os.path.join(self.workdir, 'repo-work')

        manifest_dir = os.path.join(self.repo_src, 'manifest')
        git_dir_base = os.path.join(self.repo_src, 'git')
        git_dirs = ['%s%d' % (git_dir_base, x) for x in range(PROJ_COUNT)]
        git_dirs += [
            os.path.join(self.repo_src, BRANCH_UNIQUE_PROJ_NAME % br)
            for br in REPO_BRANCHES
        ]

        for d in git_dirs + [manifest_dir, self.repo_work]:
            if not os.path.exists(d):
                os.makedirs(d)

        for d in git_dirs + [manifest_dir]:
            self.assertFalse(_cmd(['git', 'init', '--quiet'], d))

        def _masterToFront(x, y):
            return int(y == 'master') - int(x == 'master')

        REPO_BRANCHES.sort(cmp=_masterToFront)

        for n, branch in enumerate(REPO_BRANCHES):
            # when n==0 we're creating master, and 'checkout -b' will fail
            self.assertFalse(
                _cmd(['git', 'checkout', '-q', '-b', branch], manifest_dir)
                and n != 0)
            fh = open(os.path.join(manifest_dir, 'default.xml'), 'w')
            fh.write(
                REPO_MANIFEST % {
                    'branch': branch,
                    'branch-unique-project': BRANCH_UNIQUE_PROJ_NAME % branch
                })
            fh.close()
            self.assertFalse(_cmd(['git', 'add', 'default.xml'], manifest_dir))
            self.assertFalse(
                _cmd(['git', 'commit', '-q', '-m', 'empty'], manifest_dir))
        # repo does something too smart with the commiter's email while switching
        # branches within the manifest project that confuses it. We need to change
        # it here before we try using the project from a repo client, else
        # `repo init` fails
        self.assertFalse(
            _cmd([
                'git', 'filter-branch', '-f', '--env-filter',
                'GIT_COMMITTER_EMAIL=no_one'
            ] + REPO_BRANCHES, manifest_dir))

        for n, branch in enumerate(REPO_BRANCHES):
            for x, git_dir in enumerate(git_dirs):
                # when n==0 we're creating master, and 'checkout -b' will fail
                self.assertFalse(
                    _cmd(['git', 'checkout', '-q', '-b', branch], git_dir)
                    and n != 0)
                fh = open(os.path.join(git_dir, 'file%d.txt' % x), 'w')
                fh.write('Contents of file%d.txt in branch %s\n' % (x, branch))
                fh.close()
                self.assertFalse(
                    _cmd(['git', 'add', 'file%d.txt' % x], git_dir))
                self.assertFalse(
                    _cmd(['git', 'commit', '-q', '-m', 'empty'], git_dir))

        cmd = [
            REPO_BIN, 'init', '--no-repo-verify', '--repo-url', REPO_URL, '-u',
            manifest_dir
        ]
        self.assertFalse(_cmd(cmd, self.repo_work))
        self.poller = RepoPoller(self.repo_src,
                                 repo_branches=REPO_BRANCHES,
                                 workdir=self.repo_work,
                                 pollInterval=999999,
                                 repo_bin=REPO_BIN,
                                 from_addr='*****@*****.**',
                                 to_addrs='*****@*****.**',
                                 smtp_host='nohost')
        self.poller.startService()

    def tearDown(self):
        self.poller.stopService()
        shutil.rmtree(self.workdir)

    def _modifySrcFile(self,
                       gitname,
                       filename,
                       comment='comment',
                       branch='master'):
        src_dir = os.path.join(self.repo_src, gitname)
        self.assertFalse(_cmd(['git', 'checkout', branch], src_dir))
        src_file = os.path.join(src_dir, filename)
        fh = open(src_file, 'a')
        fh.write('A change to %s.' % filename)
        fh.close()
        self.assertFalse(_cmd(['git', 'add', filename], src_dir))
        self.assertFalse(_cmd(['git', 'commit', '-q', '-m', comment], src_dir))

    @defer.deferredGenerator
    def test1_simple(self):
        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()
        self.assertEqual(
            len(self.poller.comparator.tag_order), INITIAL_REVS_DETECTED,
            "%d initial revisions in repo checkout." % INITIAL_REVS_DETECTED)

    @defer.deferredGenerator
    def test2_single_change(self):
        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        self._modifySrcFile('git2', 'file2.txt', 'comment2')

        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()
        self.assertEqual(
            len(self.poller.comparator.tag_order), INITIAL_REVS_DETECTED + 1,
            "%d total revisions after a single commit." %
            (INITIAL_REVS_DETECTED + 1))
        self.assertEqual(len(self.poller.master.changes), 1,
                         "One change in master")
        change = self.poller.master.changes[0][1]
        self.assertEqual(change['files'], ['file2.txt'], 'File(s) in change.')
        self.assertEqual(change['repository'],
                         os.path.join(self.repo_src, 'git2'),
                         'Repository for change.')
        self.assertEqual(change['comments'], 'comment2', 'Change comments')

    @defer.deferredGenerator
    def test3_multiple_changes(self):
        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        self._modifySrcFile('git1', 'file1.txt')

        d = task.deferLater(
            reactor,
            2,
            self._modifySrcFile,
            'git2',
            'file2.txt',
        )
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        d = task.deferLater(reactor, 2, self._modifySrcFile, 'git0',
                            'file0.txt')
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        self.assertEqual(
            len(self.poller.comparator.tag_order), INITIAL_REVS_DETECTED + 3,
            "%d total revisions after three commits." %
            (INITIAL_REVS_DETECTED + 3))
        self.assertEqual(len(self.poller.master.changes), 3,
                         "Three changes in master")
        self.assertEqual(self.poller.master.changes[0][1]['repository'],
                         os.path.join(self.repo_src, 'git0'),
                         'Commit ordering by timestamp')
        self.assertEqual(self.poller.master.changes[1][1]['repository'],
                         os.path.join(self.repo_src, 'git1'),
                         'Commit ordering by timestamp')
        self.assertEqual(self.poller.master.changes[2][1]['repository'],
                         os.path.join(self.repo_src, 'git2'),
                         'Commit ordering by timestamp')

    @defer.deferredGenerator
    def test4_stable_sort(self):
        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        # Create enough commits to make sure their are timestamp collisions
        for i in range(5):
            self._modifySrcFile('git1', 'file1.txt', 'c%d' % i)

        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        comments = [
            change[1]['comments'] for change in self.poller.master.changes
        ]
        self.assertEqual(comments, ['c%d' % i for i in range(5)],
                         'Stable sort')

    @defer.deferredGenerator
    def test5_err_notification(self):
        # Poll once to make sure working dir is initialized
        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        # Trigger errors in polling by messing up working dir
        shutil.rmtree(os.path.join(self.repo_work, '.repo'))

        for i in range(1, 4):
            d = self.poller.poll()
            d.addErrback(lambda failure: True)
            wfd = defer.waitForDeferred(d)
            yield wfd
            wfd.getResult()
            self.assertEqual(self.poller.errCount, i * len(REPO_BRANCHES),
                             'Error count')

        self.assertEqual(len(SENT_MAILS), len(REPO_BRANCHES))
        self.assertEqual(
            SENT_MAILS[0][0:3],
            ('nohost', '*****@*****.**', '*****@*****.**'))

    @defer.deferredGenerator
    def test6_multiple_repo_branches(self):
        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        self._modifySrcFile('git1', 'file1.txt', branch='foo_branch')
        self._modifySrcFile('git2', 'file2.txt', branch='bar_branch')

        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        ch1 = self.poller.master.changes[0][1]
        self.assertEqual(ch1['properties']['manifest_branch'], 'foo_branch')

        ch2 = self.poller.master.changes[1][1]
        self.assertEqual(ch2['properties']['manifest_branch'], 'bar_branch')

        # a second round of different changes
        self._modifySrcFile('git0', 'file0.txt', branch='bar_branch')
        self._modifySrcFile('git1', 'file1.txt', branch='master')

        d = self.poller.poll()
        wfd = defer.waitForDeferred(d)
        yield wfd
        wfd.getResult()

        # branches are polled in the order passed, in this case, REPO_BRANCHES'
        ch1 = self.poller.master.changes[2][1]
        self.assertEqual(ch1['properties']['manifest_branch'], 'master')

        ch2 = self.poller.master.changes[3][1]
        self.assertEqual(ch2['properties']['manifest_branch'], 'bar_branch')
Ejemplo n.º 4
0
class TestRepoPoller(unittest.TestCase):

  def setUp(self):
    self.workdir = tempfile.mkdtemp(prefix='repo_poller_simple_test')
    self.repo_src = os.path.join(self.workdir, 'repo-src')
    self.repo_work = os.path.join(self.workdir, 'repo-work')

    manifest_dir = os.path.join(self.repo_src, 'manifest')
    git_dir_base = os.path.join(self.repo_src, 'git')
    git_dirs = ['%s%d' % (git_dir_base, x) for x in range(PROJ_COUNT)]
    git_dirs += [os.path.join(self.repo_src, BRANCH_UNIQUE_PROJ_NAME % br)
                 for br in REPO_BRANCHES]

    for d in git_dirs + [manifest_dir, self.repo_work]:
      if not os.path.exists(d):
        os.makedirs(d)

    for d in git_dirs + [manifest_dir]:
      self.assertFalse(_cmd(['git', 'init', '--quiet'], d))

    def _masterToFront(x, y): return int(y == 'master') - int(x == 'master')
    REPO_BRANCHES.sort(cmp=_masterToFront)

    for n, branch in enumerate(REPO_BRANCHES):
      # when n==0 we're creating master, and 'checkout -b' will fail
      self.assertFalse(_cmd(['git', 'checkout', '-q', '-b', branch],
                            manifest_dir)
                       and n != 0)
      fh = open(os.path.join(manifest_dir, 'default.xml'), 'w')
      fh.write(REPO_MANIFEST %
               {'branch': branch,
                'branch-unique-project': BRANCH_UNIQUE_PROJ_NAME % branch})
      fh.close()
      self.assertFalse(_cmd(['git', 'add', 'default.xml'], manifest_dir))
      self.assertFalse(_cmd(['git', 'commit', '-q', '-m', 'empty'],
                            manifest_dir))
    # repo does something too smart with the commiter's email while switching
    # branches within the manifest project that confuses it. We need to change
    # it here before we try using the project from a repo client, else
    # `repo init` fails
    self.assertFalse(_cmd(['git', 'filter-branch', '-f', '--env-filter',
                           'GIT_COMMITTER_EMAIL=no_one'] + REPO_BRANCHES,
                          manifest_dir))

    for n, branch in enumerate(REPO_BRANCHES):
      for x, git_dir in enumerate(git_dirs):
        # when n==0 we're creating master, and 'checkout -b' will fail
        self.assertFalse(_cmd(['git', 'checkout', '-q', '-b', branch], git_dir)
                         and n != 0)
        fh = open(os.path.join(git_dir, 'file%d.txt' % x), 'w')
        fh.write('Contents of file%d.txt in branch %s\n' % (x, branch))
        fh.close()
        self.assertFalse(_cmd(['git', 'add', 'file%d.txt' % x], git_dir))
        self.assertFalse(_cmd(['git', 'commit', '-q', '-m', 'empty'], git_dir))


    cmd = [REPO_BIN, 'init', '--no-repo-verify',
           '--repo-url', REPO_URL, '-u', manifest_dir]
    self.assertFalse(_cmd(cmd, self.repo_work))
    self.poller = RepoPoller(self.repo_src, repo_branches=REPO_BRANCHES,
                             workdir=self.repo_work, pollInterval=999999,
                             repo_bin=REPO_BIN, from_addr='*****@*****.**',
                             to_addrs='*****@*****.**',
                             smtp_host='nohost')
    self.poller.startService()

  def tearDown(self):
    self.poller.stopService()
    shutil.rmtree(self.workdir)

  def _modifySrcFile(self, gitname, filename, comment='comment',
                     branch='master'):
    src_dir = os.path.join(self.repo_src, gitname)
    self.assertFalse(_cmd(['git', 'checkout', branch], src_dir))
    src_file = os.path.join(src_dir, filename)
    fh = open(src_file, 'a')
    fh.write('A change to %s.' % filename)
    fh.close()
    self.assertFalse(_cmd(['git', 'add', filename], src_dir))
    self.assertFalse(_cmd(['git', 'commit', '-q', '-m', comment], src_dir))

  @defer.deferredGenerator
  def test1_simple(self):
    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()
    self.assertEqual(
        len(self.poller.comparator.tag_order), INITIAL_REVS_DETECTED,
        "%d initial revisions in repo checkout." % INITIAL_REVS_DETECTED)

  @defer.deferredGenerator
  def test2_single_change(self):
    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    self._modifySrcFile('git2', 'file2.txt', 'comment2')

    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()
    self.assertEqual(
        len(self.poller.comparator.tag_order), INITIAL_REVS_DETECTED + 1,
        "%d total revisions after a single commit." %
        (INITIAL_REVS_DETECTED + 1))
    self.assertEqual(len(self.poller.master.changes), 1,
                     "One change in master")
    change = self.poller.master.changes[0][1]
    self.assertEqual(change['files'], ['file2.txt'],
                     'File(s) in change.')
    self.assertEqual(change['repository'], os.path.join(self.repo_src, 'git2'),
                     'Repository for change.')
    self.assertEqual(change['comments'], 'comment2',
                     'Change comments')

  @defer.deferredGenerator
  def test3_multiple_changes(self):
    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    self._modifySrcFile('git1', 'file1.txt')

    d = task.deferLater(reactor, 2, self._modifySrcFile, 'git2', 'file2.txt', )
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    d = task.deferLater(reactor, 2, self._modifySrcFile, 'git0', 'file0.txt')
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    self.assertEqual(
      len(self.poller.comparator.tag_order), INITIAL_REVS_DETECTED + 3,
      "%d total revisions after three commits." % (INITIAL_REVS_DETECTED + 3))
    self.assertEqual(len(self.poller.master.changes), 3,
                     "Three changes in master")
    self.assertEqual(self.poller.master.changes[0][1]['repository'],
                     os.path.join(self.repo_src, 'git0'),
                     'Commit ordering by timestamp')
    self.assertEqual(self.poller.master.changes[1][1]['repository'],
                     os.path.join(self.repo_src, 'git1'),
                     'Commit ordering by timestamp')
    self.assertEqual(self.poller.master.changes[2][1]['repository'],
                     os.path.join(self.repo_src, 'git2'),
                     'Commit ordering by timestamp')

  @defer.deferredGenerator
  def test4_stable_sort(self):
    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    # Create enough commits to make sure their are timestamp collisions
    for i in range(5):
      self._modifySrcFile('git1', 'file1.txt', 'c%d' % i)

    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    comments = [change[1]['comments'] for change in self.poller.master.changes]
    self.assertEqual(comments, ['c%d' % i for i in range(5)],
                     'Stable sort')

  @defer.deferredGenerator
  def test5_err_notification(self):
    # Poll once to make sure working dir is initialized
    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    # Trigger errors in polling by messing up working dir
    shutil.rmtree(os.path.join(self.repo_work, '.repo'))

    for i in range(1, 4):
      d = self.poller.poll()
      d.addErrback(lambda failure: True)
      wfd = defer.waitForDeferred(d)
      yield wfd
      wfd.getResult()
      self.assertEqual(self.poller.errCount, i * len(REPO_BRANCHES),
                       'Error count')

    self.assertEqual(len(SENT_MAILS), len(REPO_BRANCHES))
    self.assertEqual(SENT_MAILS[0][0:3],
                     ('nohost', '*****@*****.**', '*****@*****.**'))

  @defer.deferredGenerator
  def test6_multiple_repo_branches(self):
    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    self._modifySrcFile('git1', 'file1.txt', branch='foo_branch')
    self._modifySrcFile('git2', 'file2.txt', branch='bar_branch')

    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    ch1 = self.poller.master.changes[0][1]
    self.assertEqual(ch1['properties']['manifest_branch'], 'foo_branch')

    ch2 = self.poller.master.changes[1][1]
    self.assertEqual(ch2['properties']['manifest_branch'], 'bar_branch')

    # a second round of different changes
    self._modifySrcFile('git0', 'file0.txt', branch='bar_branch')
    self._modifySrcFile('git1', 'file1.txt', branch='master')

    d = self.poller.poll()
    wfd = defer.waitForDeferred(d)
    yield wfd
    wfd.getResult()

    # branches are polled in the order passed, in this case, REPO_BRANCHES'
    ch1 = self.poller.master.changes[2][1]
    self.assertEqual(ch1['properties']['manifest_branch'], 'master')

    ch2 = self.poller.master.changes[3][1]
    self.assertEqual(ch2['properties']['manifest_branch'], 'bar_branch')