Example #1
0
def create_and_upstream_gecko_bug(env, git_gecko, git_wpt, hg_gecko_upstream,
                                  upstream_gecko_commit):
    # Create gecko bug and upstream it
    bug = 1234
    test_changes = {"README": b"Change README\n"}
    upstream_gecko_commit(test_changes=test_changes, bug=bug,
                          message=b"Change README")

    test_changes = {"CONFIG": b"Change CONFIG\n"}
    rev = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                message=b"Change CONFIG")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    sync = syncs["open"].pop()
    env.gh_wpt.get_pull(sync.pr).mergeable = True

    hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    upstream.gecko_push(git_gecko, git_wpt, "mozilla-central", rev, raise_on_error=True)

    return sync
Example #2
0
def test_create_partial_backout_reland(git_gecko, git_wpt, upstream_gecko_commit,
                                       upstream_gecko_backout):
    bug = "1234"
    test_changes = {"README": "Change README\n"}
    rev0 = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                 message="Change README")
    rev1 = upstream_gecko_commit(test_changes={"README": "Change README again\n"}, bug=bug,
                                 message="Change README again")

    update_repositories(git_gecko, git_wpt)
    upstream.gecko_push(git_gecko, git_wpt, "inbound", rev1, raise_on_error=True)

    upstream_gecko_backout(rev1, bug)

    # Make some unrelated commit in the root
    upstream_gecko_commit(other_changes=test_changes, bug="1235",
                          message="Change other file")

    relanding_rev = upstream_gecko_commit(test_changes={"README": "Change README once more\n"},
                                          bug=bug,
                                          message="Change README once more")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=relanding_rev)
    upstream.gecko_push(git_gecko, git_wpt, "inbound", relanding_rev, raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["open"]
    assert len(syncs["open"]) == 1
    sync = syncs["open"][0]
    assert sync.bug == "1234"
    assert len(sync.gecko_commits) == 2
    assert len(sync.wpt_commits) == 2
    assert sync.status == "open"
    sync.wpt_commits[0].metadata["gecko-commit"] == rev0
    sync.wpt_commits[1].metadata["gecko-commit"] == relanding_rev
Example #3
0
def test_upstream_reprocess_commits(git_gecko, git_wpt, upstream_gecko_commit,
                                    upstream_gecko_backout):
    bug = "1234"
    test_changes = {"README": "Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                message="Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "inbound", rev,
                                       raise_on_error=True)
    sync = pushed.pop()
    assert sync.gecko_commits[0].upstream_sync(git_gecko, git_wpt) == sync

    backout_rev = upstream_gecko_backout(rev, bug)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=backout_rev)
    upstream.gecko_push(git_gecko, git_wpt, "inbound", backout_rev, raise_on_error=True)

    sync_point = git_gecko.refs["sync/upstream/inbound"]
    sync_point.commit = (sync_commit.GeckoCommit(git_gecko, git_gecko.cinnabar.hg2git(rev))
                         .commit.parents[0])

    pushed, landed, failed = upstream.gecko_push(git_gecko, git_wpt, "inbound", backout_rev,
                                                 raise_on_error=True)
    assert len(pushed) == len(landed) == len(failed) == 0
Example #4
0
def test_land_pr(env, git_gecko, git_wpt, hg_gecko_upstream, upstream_gecko_commit):
    bug = "1234"
    test_changes = {"README": "Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                message="Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko, git_wpt, "inbound", rev,
                                                 raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["open"]
    assert len(syncs["open"]) == 1
    sync = syncs["open"][0]
    env.gh_wpt.get_pull(sync.pr).mergeable = True
    original_remote_branch = sync.remote_branch

    hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko, git_wpt, "central", rev,
                                                 raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs == {"wpt-merged": [sync]}
    assert sync.gecko_landed()
    assert sync.status == "wpt-merged"
    assert original_remote_branch not in git_wpt.remotes.origin.refs
    pr = env.gh_wpt.get_pull(sync.pr)
    assert pr.merged
Example #5
0
def test_no_upstream_downstream(env, git_gecko, git_wpt, upstream_gecko_commit,
                                upstream_gecko_backout):

    hg_rev = upstream_gecko_commit(test_changes={"README": "Example change"},
                                   message="""Example change

wpt-pr: 1
wpt-commits: 0000000000000000000000000000000000000000""")
    update_repositories(git_gecko, git_wpt, wait_gecko_commit=hg_rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "autoland",
                                                 hg_rev,
                                                 raise_on_error=True)
    assert not pushed
    assert not landed
    assert not failed
    backout_rev = upstream_gecko_backout(hg_rev, "1234")
    update_repositories(git_gecko, git_wpt, wait_gecko_commit=backout_rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "autoland",
                                                 backout_rev,
                                                 raise_on_error=True)
    assert not pushed
    assert not landed
    assert not failed
Example #6
0
def test_upstream_existing(env, git_gecko, git_wpt, upstream_gecko_commit,
                           upstream_wpt_commit):
    bug = "1234"
    test_changes_1 = {"README": "Change README\n"}
    upstream_gecko_commit(test_changes=test_changes_1,
                          bug=bug,
                          message="Change README")
    test_changes_2 = {"OTHER": "Add other file\n"}
    gecko_rev_2 = upstream_gecko_commit(test_changes=test_changes_2,
                                        bug=bug,
                                        message="Add other")

    upstream_wpt_commit(file_data=test_changes_1)
    update_repositories(git_gecko, git_wpt, wait_gecko_commit=gecko_rev_2)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "autoland",
                                                 gecko_rev_2,
                                                 raise_on_error=True)
    assert len(pushed) == 1
    assert len(landed) == 0
    assert len(failed) == 0

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    sync = pushed.pop()
    assert syncs == {"open": {sync}}
    assert sync.bug == "1234"
    assert sync.status == "open"
    assert len(sync.gecko_commits) == 2
    assert len(sync.wpt_commits) == 1
    assert sync.gecko_commits.head.sha1 == git_gecko.cinnabar.hg2git(
        gecko_rev_2)

    wpt_commit = sync.wpt_commits[0]

    assert wpt_commit.msg.split("\n")[0] == "Add other"
    assert "OTHER" in wpt_commit.commit.tree
    assert wpt_commit.metadata == {
        'gecko-integration-branch': 'autoland',
        'bugzilla-url':
        'https://bugzilla-dev.allizom.org/show_bug.cgi?id=1234',
        'gecko-commit': gecko_rev_2
    }

    # Now make another push to the same bug and check we handle it correctly

    test_changes_3 = {"YET_ANOTHER": "Add more files\n"}
    gecko_rev_3 = upstream_gecko_commit(test_changes=test_changes_3,
                                        bug=bug,
                                        message="Add more")
    update_repositories(git_gecko, git_wpt, wait_gecko_commit=gecko_rev_3)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "autoland",
                                                 gecko_rev_3,
                                                 raise_on_error=True)
    assert len(sync.gecko_commits) == 3
    assert len(sync.wpt_commits) == 2
    assert ([item.metadata.get("gecko-commit")
             for item in sync.wpt_commits] == [gecko_rev_2, gecko_rev_3])
Example #7
0
def setup_repo(env, git_wpt, git_gecko, hg_gecko_upstream, upstream_gecko_commit):
    bug = "1234"
    changes = {"README": "Changes to README\n"}
    upstream_gecko_commit(test_changes=changes, bug=bug,
                          message="Change README")

    test_changes = {"CONFIG": "Change CONFIG\n"}
    rev = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                message="Change CONFIG")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    upstream.gecko_push(git_gecko, git_wpt, "autoland", rev, raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    sync = syncs["open"].pop()
    env.gh_wpt.get_pull(sync.pr).mergeable = True

    hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "central",
                                                 rev,
                                                 raise_on_error=True)
    assert len(pushed) == 0
    assert len(landed) == 1
    assert len(failed) == 0

    # Push the commits to upstream wpt
    with SyncLock.for_process(sync.process_name) as upstream_sync_lock:
        with sync.as_mut(upstream_sync_lock):
            sync.push_commits()

    return list(landed)[0]
Example #8
0
def test_land_pr_after_status_change(env, git_gecko, git_wpt,
                                     hg_gecko_upstream, upstream_gecko_commit):
    bug = "1234"
    test_changes = {"README": "Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes,
                                bug=bug,
                                message="Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "autoland",
                                                 rev,
                                                 raise_on_error=True)
    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["open"]
    assert len(syncs["open"]) == 1
    sync = syncs["open"].pop()
    env.gh_wpt.get_pull(sync.pr).mergeable = True

    env.gh_wpt.set_status(sync.pr, "failure", "http://test/", "tests failed",
                          "continuous-integration/travis-ci/pr")
    with SyncLock("upstream", None) as lock:
        with sync.as_mut(lock):
            upstream.commit_status_changed(
                git_gecko, git_wpt, sync,
                "continuous-integration/travis-ci/pr", "failure",
                "http://test/", sync.wpt_commits.head.sha1)

    assert sync.last_pr_check == {
        "state": "failure",
        "sha": sync.wpt_commits.head.sha1
    }
    hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "mozilla-central",
                                                 rev,
                                                 raise_on_error=True)

    env.gh_wpt.set_status(sync.pr, "success", "http://test/", "tests failed",
                          "continuous-integration/travis-ci/pr")

    with SyncLock("upstream", None) as lock:
        with sync.as_mut(lock):
            upstream.commit_status_changed(
                git_gecko, git_wpt, sync,
                "continuous-integration/travis-ci/pr", "success",
                "http://test/", sync.wpt_commits.head.sha1)

    assert sync.last_pr_check == {
        "state": "success",
        "sha": sync.wpt_commits.head.sha1
    }
    assert sync.gecko_landed()
    assert sync.status == "wpt-merged"
Example #9
0
def test_land_pr_after_status_change(env, git_gecko, git_wpt,
                                     hg_gecko_upstream, upstream_gecko_commit,
                                     set_pr_status):
    bug = 1234
    test_changes = {"README": b"Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes,
                                bug=bug,
                                message=b"Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "autoland",
                                                 rev,
                                                 raise_on_error=True)
    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert list(syncs.keys()) == ["open"]
    assert len(syncs["open"]) == 1
    sync = syncs["open"].pop()
    env.gh_wpt.get_pull(sync.pr).mergeable = True

    set_pr_status(sync.pr, "failure")
    with SyncLock("upstream", None) as lock:
        with sync.as_mut(lock):
            upstream.commit_check_changed(git_gecko, git_wpt, sync)

    pr = env.gh_wpt.get_pull(sync.pr)
    assert sync.last_pr_check == {
        "state": "failure",
        "sha": pr._commits[-1].sha
    }
    hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "mozilla-central",
                                                 rev,
                                                 raise_on_error=True)

    set_pr_status(sync.pr, "success")

    with SyncLock("upstream", None) as lock:
        with sync.as_mut(lock):
            upstream.commit_check_changed(git_gecko, git_wpt, sync)

    assert sync.last_pr_check == {
        "state": "success",
        "sha": pr._commits[-1].sha
    }
    assert sync.gecko_landed()
    assert sync.status == "wpt-merged"
Example #10
0
def test_land_pr(env, git_gecko, git_wpt, hg_gecko_upstream,
                 upstream_gecko_commit):
    bug = "1234"
    test_changes = {"README": "Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes,
                                bug=bug,
                                message="Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "autoland",
                                                 rev,
                                                 raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["open"]
    assert len(syncs["open"]) == 1
    sync = syncs["open"].pop()
    env.gh_wpt.get_pull(sync.pr).mergeable = True
    original_remote_branch = sync.remote_branch

    hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "mozilla-central",
                                                 rev,
                                                 raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs == {"wpt-merged": {sync}}
    assert sync.gecko_landed()
    assert sync.status == "wpt-merged"
    assert original_remote_branch not in git_wpt.remotes.origin.refs
    pr = env.gh_wpt.get_pull(sync.pr)
    assert pr.merged

    with SyncLock.for_process(sync.process_name) as lock:
        with sync.as_mut(lock):
            upstream.update_pr(git_gecko, git_wpt, sync, "closed",
                               pr["merge_commit_sha"], '',
                               pr["merged_by"]["login"])

    user = env.config["web-platform-tests"]["github"]["user"]
    assert ("Upstream PR merged by %s" %
            user) in env.bz.output.getvalue().strip().split('\n')
Example #11
0
def test_delete(env, git_gecko, git_wpt, upstream_gecko_commit):
    # Do some stuff to create an example sync
    bug = 1234
    test_changes = {"README": b"Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes,
                                bug=bug,
                                message=b"Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    _, _, _ = upstream.gecko_push(git_gecko,
                                  git_wpt,
                                  "autoland",
                                  rev,
                                  raise_on_error=True)

    sync = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug,
                                         flat=True).pop()
    process_name = sync.process_name

    sync_path = "/".join(str(item) for item in process_name.as_tuple())

    ref = git.Reference(git_gecko, "refs/syncs/data")
    assert ref.commit.tree[sync_path]

    gecko_ref = git.Reference(git_gecko, "refs/heads/%s" % sync_path)
    assert gecko_ref.is_valid()

    wpt_ref = git.Reference(git_wpt, "refs/heads/%s" % sync_path)
    assert wpt_ref.is_valid()

    with SyncLock.for_process(process_name) as lock:
        with sync.as_mut(lock):
            sync.delete()

    for idx_cls in (index.SyncIndex, index.PrIdIndex, index.BugIdIndex):
        idx = idx_cls(git_gecko)
        assert not idx.get(idx.make_key(sync))

    ref = git.Reference(git_gecko, "refs/syncs/data")
    with pytest.raises(KeyError):
        ref.commit.tree[sync_path]

    ref = git.Reference(git_gecko, "refs/heads/%s" % sync_path)
    assert not ref.is_valid()

    ref = git.Reference(git_wpt, "refs/heads/%s" % sync_path)
    assert not ref.is_valid()
Example #12
0
def test_create_pr_backout(git_gecko, git_wpt, upstream_gecko_commit,
                           upstream_gecko_backout):
    bug = "1234"
    test_changes = {"README": "Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes,
                                bug=bug,
                                message="Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    upstream.gecko_push(git_gecko,
                        git_wpt,
                        "autoland",
                        rev,
                        raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["open"]
    assert len(syncs["open"]) == 1
    sync = syncs["open"].pop()
    assert sync.bug == "1234"
    assert sync.status == "open"
    assert len(sync.gecko_commits) == 1
    assert len(sync.wpt_commits) == 1
    assert sync.pr

    backout_rev = upstream_gecko_backout(rev, bug)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=backout_rev)
    upstream.gecko_push(git_gecko,
                        git_wpt,
                        "autoland",
                        backout_rev,
                        raise_on_error=True)
    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["incomplete"]
    assert len(syncs["incomplete"]) == 1
    sync = syncs["incomplete"].pop()
    assert sync.bug == "1234"
    assert len(sync.gecko_commits) == 0
    assert len(sync.wpt_commits) == 1
    assert len(sync.upstreamed_gecko_commits) == 1
    assert sync.status == "incomplete"
    backout_commit = sync_commit.GeckoCommit(git_gecko,
                                             git_gecko.cinnabar.hg2git(rev))
    assert backout_commit.upstream_sync(git_gecko, git_wpt) == sync
Example #13
0
def test_create_pr(env, git_gecko, git_wpt, upstream_gecko_commit):
    bug = "1234"
    test_changes = {"README": "Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes,
                                bug=bug,
                                message="Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, landed, failed = upstream.gecko_push(git_gecko,
                                                 git_wpt,
                                                 "autoland",
                                                 rev,
                                                 raise_on_error=True)
    assert len(pushed) == 1
    assert len(landed) == 0
    assert len(failed) == 0

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["open"]
    assert len(syncs["open"]) == 1
    sync = syncs["open"].pop()
    assert sync.bug == "1234"
    assert sync.status == "open"
    assert len(sync.gecko_commits) == 1
    assert len(sync.wpt_commits) == 1
    assert sync.gecko_commits.head.sha1 == git_gecko.cinnabar.hg2git(rev)

    wpt_commit = sync.wpt_commits[0]

    assert wpt_commit.msg.split("\n")[0] == "Change README"
    assert "README" in wpt_commit.commit.tree
    assert wpt_commit.metadata == {
        'gecko-integration-branch': 'autoland',
        'bugzilla-url':
        'https://bugzilla-dev.allizom.org/show_bug.cgi?id=1234',
        'gecko-commit': rev
    }
    assert sync.pr
    assert "Posting to bug %s" % bug in env.bz.output.getvalue()
    assert "Created PR with id %s" % sync.pr in env.gh_wpt.output.getvalue()
    assert sync.gecko_commits[0].upstream_sync(git_gecko, git_wpt) == sync
Example #14
0
def test_create_pr_backout_reland(git_gecko, git_wpt, upstream_gecko_commit,
                                  upstream_gecko_backout):
    bug = "1234"
    test_changes = {"README": "Change README\n"}
    rev = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                message="Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    upstream.gecko_push(git_gecko, git_wpt, "inbound", rev,
                        raise_on_error=True)

    backout_rev = upstream_gecko_backout(rev, bug)

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    upstream.gecko_push(git_gecko, git_wpt, "inbound", backout_rev, raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["incomplete"]
    assert len(syncs["incomplete"]) == 1
    sync = syncs["incomplete"][0]
    assert sync.status == "incomplete"
    assert sync._process_name.seq_id == 0
    assert len(sync.gecko_commits) == 0
    assert len(sync.upstreamed_gecko_commits) == 1
    assert len(sync.wpt_commits) == 1

    # Make some unrelated commit in the root
    upstream_gecko_commit(other_changes=test_changes, bug="1235",
                          message="Change other file")

    relanding_rev = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                          message="Reland: Change README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    upstream.gecko_push(git_gecko, git_wpt, "inbound", relanding_rev, raise_on_error=True)

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert syncs.keys() == ["open"]
    assert len(syncs["open"]) == 1
    sync = syncs["open"][0]
    assert sync._process_name.seq_id == 0
    assert sync.bug == "1234"
    assert len(sync.gecko_commits) == 1
    assert len(sync.wpt_commits) == 1
    assert len(sync.upstreamed_gecko_commits) == 1
    assert sync.status == "open"
    sync.wpt_commits[0].metadata["gecko-commit"] == relanding_rev
Example #15
0
def test_landing_reapply(env, git_gecko, git_wpt, git_wpt_upstream, pull_request, set_pr_status,
                         hg_gecko_upstream, upstream_gecko_commit, upstream_wpt_commit,
                         hg_gecko_try, mock_mach, mock_tasks):
    # Test that we reapply the correct commits when landing patches on upstream
    # First we need to create 3 gecko commits:
    # Two that are landed
    # One that is still a PR
    # Then we create a landing that points at the first gecko commit that is landed
    # upstream. Locally we expect the code to reapply the two other gecko commits, so
    # we should end up with no overall change.

    trypush.Mach = mock_mach

    # Add first gecko change
    test_changes = {"change1": b"CHANGE1\n"}
    rev = upstream_gecko_commit(test_changes=test_changes, bug=1111,
                                message=b"Add change1 file")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev,
                                       raise_on_error=True)
    sync_1 = pushed.pop()

    # Update central
    hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

    # Merge the upstream change
    with SyncLock.for_process(sync_1.process_name) as lock:
        with sync_1.as_mut(lock):
            remote_branch = sync_1.remote_branch
            git_wpt_upstream.git.checkout(remote_branch)
            git_wpt_upstream.git.rebase("master")
            git_wpt_upstream.git.checkout("master")
            git_wpt_upstream.git.merge(remote_branch, ff_only=True)

            sync_1.finish()

    # Add second gecko change
    test_changes = {"change2": b"CHANGE2\n"}
    rev = upstream_gecko_commit(test_changes=test_changes, bug=1112,
                                message=b"Add change2 file")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev,
                                       raise_on_error=True)
    sync_2 = pushed.pop()

    hg_gecko_upstream.bookmark("mozilla/central", "-r", rev)

    # Merge the gecko change
    remote_branch = sync_2.remote_branch
    git_wpt_upstream.git.checkout(remote_branch)
    git_wpt_upstream.git.rebase("master")
    git_wpt_upstream.git.checkout("master")
    git_wpt_upstream.git.merge(remote_branch, ff_only=True)

    # Add an upstream commit that has metadata
    pr = pull_request([(b"Upstream change 1", {"upstream1": b"UPSTREAM1\n"})])
    head_rev = pr._commits[0]["sha"]
    downstream.new_wpt_pr(git_gecko, git_wpt, pr)
    downstream_sync = set_pr_status(pr.number, "success")
    git_wpt_upstream.head.commit = head_rev
    git_wpt_upstream.git.reset(hard=True)
    with SyncLock.for_process(downstream_sync.process_name) as downstream_lock:
        with downstream_sync.as_mut(downstream_lock):
            downstream_sync.data["force-metadata-ready"] = True

    # This is the commit we should land to
    landing_rev = git_wpt_upstream.git.rev_parse("HEAD")

    # Add an upstream commit that doesn't have metadata
    pr = pull_request([(b"Upstream change 2", {"upstream2": b"UPSTREAM2\n"})])
    head_rev = pr._commits[0]["sha"]
    downstream.new_wpt_pr(git_gecko, git_wpt, pr)
    downstream_sync = set_pr_status(pr.number, "success")
    git_wpt_upstream.head.commit = head_rev
    git_wpt_upstream.git.reset(hard=True)

    # Add third gecko change
    test_changes = {"change3": b"CHANGE3\n"}
    rev = upstream_gecko_commit(test_changes=test_changes, bug=1113,
                                message=b"Add change3 file")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev)
    pushed, _, _ = upstream.gecko_push(git_gecko, git_wpt, "autoland", rev,
                                       raise_on_error=True)

    # Now start a landing
    tree.is_open = lambda x: True
    sync = landing.update_landing(git_gecko, git_wpt)

    assert sync is not None

    for i in xrange(2):
        with SyncLock.for_process(sync.process_name) as lock:
            try_push = sync.latest_try_push
            with sync.as_mut(lock), try_push.as_mut(lock):
                try_push.taskgroup_id = "abcde" + str(i)
                try_push.download_logs = Mock(return_value=[])
                with patch.object(tc.TaskGroup, "tasks",
                                  property(Mock(return_value=mock_tasks(completed=["foo"])))):
                    landing.try_push_complete(git_gecko, git_wpt, try_push, sync)

    hg_gecko_upstream.update()
    gecko_root = hg_gecko_upstream.root().strip().decode("utf8")
    assert (hg_gecko_upstream
            .log("-l1", "--template={desc|firstline}")
            .strip()
            .endswith(b"[wpt-sync] Update web-platform-tests to %s, a=testonly" %
                      landing_rev.encode("utf8")))
    for file in ["change1", "change2", "change3", "upstream1"]:
        path = os.path.join(gecko_root,
                            env.config["gecko"]["path"]["wpt"],
                            file)
        assert os.path.exists(path)
        with open(path) as f:
            assert f.read() == file.upper() + "\n"
    assert not os.path.exists(os.path.join(gecko_root,
                                           env.config["gecko"]["path"]["wpt"],
                                           "upstream2"))
    sync_point = landing.load_sync_point(git_gecko, git_wpt)
    assert sync_point["upstream"] == landing_rev
Example #16
0
def test_upstream_multi(env, git_gecko, git_wpt, upstream_gecko_commit):
    bug = "1234"
    test_changes = {"README": "Add README\n"}
    rev_0 = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                  message="Add README")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev_0)
    pushed, landed, failed = upstream.gecko_push(git_gecko, git_wpt, "inbound", rev_0,
                                                 raise_on_error=True)
    assert len(pushed) == 1
    sync_0 = pushed.pop()

    test_changes = {"README1": "Add README1\n"}
    rev_1 = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                  message="Add README1")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev_1)
    pushed, landed, failed = upstream.gecko_push(git_gecko, git_wpt, "inbound", rev_1,
                                                 raise_on_error=True)
    assert len(pushed) == 1
    assert pushed == {sync_0}
    assert len(sync_0.upstreamed_gecko_commits) == 2
    assert sync_0._process_name.seq_id == 0

    sync_0.finish("wpt-merged")
    assert sync_0.status == "wpt-merged"

    # Add new files each time to avoid conflicts since we don't
    # Actually do the merges
    test_changes = {"README2": "Add README2\n"}
    rev_2 = upstream_gecko_commit(test_changes=test_changes,
                                  bug=bug,
                                  message="Add README2")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev_2)
    pushed, landed, failed = upstream.gecko_push(git_gecko, git_wpt, "inbound", rev_2,
                                                 raise_on_error=True)

    assert len(pushed) == 1
    sync_1 = pushed.pop()
    assert sync_1 != sync_0
    assert sync_1._process_name.seq_id == 1

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert set(syncs.keys()) == {"open", "wpt-merged"}
    assert set(syncs["open"]) == {sync_1}
    assert set(syncs["wpt-merged"]) == {sync_0}

    sync_0.finish()
    sync_1.finish()

    test_changes = {"README3": "Add README3\n"}
    rev_3 = upstream_gecko_commit(test_changes=test_changes, bug=bug,
                                  message="Add README3")

    update_repositories(git_gecko, git_wpt, wait_gecko_commit=rev_3)
    pushed, landed, failed = upstream.gecko_push(git_gecko, git_wpt, "inbound", rev_3,
                                                 raise_on_error=True)
    assert len(pushed) == 1
    sync_2 = pushed.pop()
    assert sync_2._process_name not in (sync_1._process_name, sync_0._process_name)
    assert sync_2._process_name.seq_id == 2

    syncs = upstream.UpstreamSync.for_bug(git_gecko, git_wpt, bug)
    assert set(syncs.keys()) == {"open", "complete"}
    assert set(syncs["open"]) == {sync_2}
    assert set(syncs["complete"]) == {sync_0, sync_1}