def test_landing_pr_on_central(env, git_gecko, git_wpt, git_wpt_upstream, pull_request, set_pr_status, upstream_gecko_commit, mock_mach): # Ensure we handle the case where a PR already identical changes on central trypush.Mach = mock_mach test_changes = {"example/test.html": b"Change test\n"} more_changes = {"LICENSE": b"Change license\n"} for changes in [test_changes, more_changes]: pr = pull_request([(b"Test commit", changes)]) downstream.new_wpt_pr(git_gecko, git_wpt, pr) downstream_sync = set_pr_status(pr.number, "success") head_rev = pr._commits[0]["sha"] git_wpt_upstream.head.commit = head_rev git_wpt.remotes.origin.fetch() landing.wpt_push(git_gecko, git_wpt, [head_rev], create_missing=False) 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 # Repeat the changes in m-c upstream_gecko_commit(test_changes=test_changes, bug=1234, message=b"Change README") tree.is_open = lambda x: True sync = landing.update_landing(git_gecko, git_wpt) assert len(sync.wpt_commits) == 2 assert len(sync.gecko_commits) == 3 assert sync.gecko_commits[0].is_empty() assert sync.gecko_commits[-1].is_landing
def test_relanding_unchanged_upstreamed_pr(env, git_gecko, git_wpt, hg_gecko_upstream, pull_request, upstream_gecko_commit, mock_mach, set_pr_status, git_wpt_upstream): trypush.Mach = mock_mach # Create an unrelated PR that didn't come from Gecko pr0 = pull_request([(b"Non Gecko PR", {"SOMEFILE": b"Made changes"})]) unrelated_rev = pr0._commits[0]["sha"] downstream.new_wpt_pr(git_gecko, git_wpt, pr0) downstream_sync = set_pr_status(pr0.number, 'success') git_wpt_upstream.head.commit = unrelated_rev git_wpt.remotes.origin.fetch() sync = create_and_upstream_gecko_bug(env, git_gecko, git_wpt, hg_gecko_upstream, upstream_gecko_commit) # 'Merge' this upstream PR pr = env.gh_wpt.get_pull(sync.pr) pr["user"]["login"] = "******" with SyncLock.for_process(sync.process_name) as upstream_sync_lock: with sync.as_mut(upstream_sync_lock): sync.push_commits() assert str(git_wpt_upstream.active_branch) == "master" git_wpt_upstream.git.merge('gecko/1234') # TODO avoid hardcoding? # Create a ref on the upstream to simulate the pr than GH would setup git_wpt_upstream.create_head( 'pr/%d' % pr['number'], commit=git_wpt_upstream.refs['gecko/1234'].commit.hexsha) git_wpt.remotes.origin.fetch() pr['merge_commit_sha'] = str(git_wpt_upstream.active_branch.commit.hexsha) pr['base'] = {'sha': unrelated_rev} env.gh_wpt.commit_prs[pr['merge_commit_sha']] = pr['number'] # Update landing, the Non Gecko PR should be applied but not the Gecko one we upstreamed def mock_create(repo, msg, metadata, author=None, amend=False, allow_empty=False): # This commit should not be making it this far, should've been dropped earlier assert b'Bug 1234 [wpt PR 2] - [Gecko Bug 1234]' not in msg return DEFAULT m = Mock(side_effect=mock_create, wraps=sync_commit.Commit.create) with patch('sync.commit.Commit.create', m): landing_sync = landing.update_landing(git_gecko, git_wpt, include_incomplete=True) commits = landing_sync.gecko_commits._commits # Check that the upstreamed gecko PR didnt get pushed to try assert not any([c.bug == sync.bug for c in commits]) # Check that our unrelated PR got pushed to try assert any([c.bug == downstream_sync.bug for c in commits])
def test_land_commit(env, git_gecko, git_wpt, git_wpt_upstream, pull_request, set_pr_status, hg_gecko_try, mock_mach, mock_tasks): pr = pull_request([(b"Test commit", {"README": b"example_change"})]) head_rev = pr._commits[0]["sha"] trypush.Mach = mock_mach 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.remotes.origin.fetch() landing.wpt_push(git_gecko, git_wpt, [head_rev], create_missing=False) 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 tree.is_open = lambda x: True sync = landing.update_landing(git_gecko, git_wpt) assert ("Setting bug %s add_blocks %s" % (sync.bug, downstream_sync.bug) in env.bz.output.getvalue()) try_push = sync.latest_try_push with SyncLock.for_process(sync.process_name) as lock: with sync.as_mut(lock), try_push.as_mut(lock): try_push.taskgroup_id = "abcdef" with patch.object(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) assert "Pushed to try (stability)" in env.bz.output.getvalue() assert try_push.status == "complete" assert sync.status == "open" try_push = sync.latest_try_push with SyncLock.for_process(sync.process_name) as lock: with sync.as_mut(lock), try_push.as_mut(lock): try_push.taskgroup_id = "abcdef2" with patch.object(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) new_head = git_gecko.remotes.mozilla.refs["bookmarks/mozilla/autoland"].commit assert "Update web-platform-tests to %s" % head_rev in new_head.message assert (new_head.tree["testing/web-platform/tests/README"].data_stream.read() == b"example_change") sync_point = landing.load_sync_point(git_gecko, git_wpt) assert sync_point["upstream"] == head_rev # Update central to contain the landing git_gecko.refs["mozilla/bookmarks/mozilla/central"].commit = new_head with patch("sync.landing.start_next_landing") as start_next_landing: landing.gecko_push(git_gecko, git_wpt, "mozilla-central", git_gecko.cinnabar.git2hg(new_head)) assert start_next_landing.call_count == 1 assert sync.status == "complete"
def test_no_download_logs_after_all_try_tasks_success(git_gecko, git_wpt, try_push, mock_tasks, env): tasks = Mock(return_value=mock_tasks(completed=["bar", "baz", "boo"])) with patch.object(tc.TaskGroup, "tasks", property(tasks)): sync = landing.update_landing(git_gecko, git_wpt) try_push.download_logs = Mock(return_value=[]) landing.try_push_complete(git_gecko, git_wpt, try_push, sync) # no intermittents in the try push try_push.download_logs.assert_not_called() assert sync.status == "open" assert try_push.status == "complete"
def test_land_try(env, git_gecko, git_wpt, git_wpt_upstream, pull_request, set_pr_status, hg_gecko_try, mock_mach): pr = pull_request([(b"Test commit", { "README": b"example_change", "resources/testdriver_vendor.js": b"Some change" })]) head_rev = pr._commits[0]["sha"] trypush.Mach = mock_mach downstream.new_wpt_pr(git_gecko, git_wpt, pr) sync = set_pr_status(pr.number, "success") git_wpt_upstream.head.commit = head_rev git_wpt.remotes.origin.fetch() landing.wpt_push(git_gecko, git_wpt, [head_rev], create_missing=False) with SyncLock.for_process(sync.process_name) as downstream_lock: with sync.as_mut(downstream_lock): sync.data["force-metadata-ready"] = True tree.is_open = lambda x: True landing_sync = landing.update_landing(git_gecko, git_wpt) assert landing_sync is not None with SyncLock("landing", None) as lock: with landing_sync.as_mut(lock): worktree = landing_sync.gecko_worktree.get() # Check that files we shouldn't move aren't assert not os.path.exists( os.path.join(worktree.working_dir, env.config["gecko"]["path"]["wpt"], ".git")) with open( os.path.join(worktree.working_dir, env.config["gecko"]["path"]["wpt"], "resources/testdriver_vendor.js"), "rb") as f: assert f.read() == b"Initial testdriver_vendor\n" try_push = sync.latest_try_push assert try_push is None mach_command = mock_mach.get_log()[-1] assert mach_command["command"] == "mach" assert mach_command["args"] == ("try", "fuzzy", "-q", "web-platform-tests !ccov !shippable", "-q", "web-platform-tests linux-32 shippable", "-q", "web-platform-tests mac !debug shippable", "--disable-target-task-filter", "--artifact")
def test_land_commit(env, git_gecko, git_wpt, git_wpt_upstream, pull_request, set_pr_status, hg_gecko_try, mock_mach, mock_tasks): pr = pull_request([("Test commit", {"README": "example_change"})]) head_rev = pr._commits[0]["sha"] trypush.Mach = mock_mach downstream.new_wpt_pr(git_gecko, git_wpt, pr) downstream_sync = set_pr_status(pr, "success") git_wpt_upstream.head.commit = head_rev git_wpt.remotes.origin.fetch() landing.wpt_push(git_gecko, git_wpt, [head_rev], create_missing=False) downstream_sync.data["force-metadata-ready"] = True tree.is_open = lambda x: True sync = landing.update_landing(git_gecko, git_wpt) # Set the landing sync point to current central sync.last_sync_point(git_gecko, "mozilla-central", env.config["gecko"]["refs"]["central"]) try_push = sync.latest_try_push try_push.taskgroup_id = "abcdef" with patch.object(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) assert sync.status == "open" new_head = git_gecko.remotes.mozilla.refs[ "bookmarks/mozilla/inbound"].commit assert "Update web-platform-tests to %s" % head_rev in new_head.message assert new_head.tree["testing/web-platform/tests/README"].data_stream.read( ) == "example_change" sync_point = landing.load_sync_point(git_gecko, git_wpt) assert sync_point["local"] == new_head.parents[0].hexsha assert sync_point["upstream"] == head_rev # Update central to contain the landing git_gecko.refs["mozilla/bookmarks/mozilla/central"].commit = new_head with patch("sync.landing.tasks.land.apply_async") as mock_apply: landing.gecko_push(git_gecko, git_wpt, "mozilla-central", git_gecko.cinnabar.git2hg(new_head)) assert mock_apply.call_count == 1 assert sync.status == "complete"
def test_landing_metadata(env, git_gecko, git_wpt, git_wpt_upstream, pull_request, set_pr_status, hg_gecko_try, mock_mach): from conftest import create_file_data, gecko_changes trypush.Mach = mock_mach pr = pull_request([("Test commit", { "example/test1.html": "example_change" })]) head_rev = pr._commits[0]["sha"] downstream.new_wpt_pr(git_gecko, git_wpt, pr) downstream_sync = set_pr_status(pr, "success") # Create a metadata commit with SyncLock.for_process(downstream_sync.process_name) as downstream_lock: with downstream_sync.as_mut(downstream_lock): git_work = downstream_sync.gecko_worktree.get() changes = gecko_changes(env, meta_changes={ "example/test1.html": "[test1.html]\n expected: FAIL" }) file_data, _ = create_file_data(changes, git_work.working_dir) downstream_sync.ensure_metadata_commit() git_work.index.add(file_data) downstream_sync._commit_metadata() assert downstream_sync.metadata_commit is not None downstream_sync.data["force-metadata-ready"] = True git_wpt_upstream.head.commit = head_rev git_wpt.remotes.origin.fetch() landing.wpt_push(git_gecko, git_wpt, [head_rev], create_missing=False) tree.is_open = lambda x: True landing_sync = landing.update_landing(git_gecko, git_wpt) assert len(landing_sync.gecko_commits) == 3 assert landing_sync.gecko_commits[-1].metadata["wpt-type"] == "landing" assert landing_sync.gecko_commits[-2].metadata["wpt-type"] == "metadata" for item in file_data: assert item in landing_sync.gecko_commits[-2].commit.stats.files
def test_relanding_changed_upstreamed_pr(env, git_gecko, git_wpt, hg_gecko_upstream, upstream_gecko_commit, mock_mach, git_wpt_upstream): trypush.Mach = mock_mach sync = create_and_upstream_gecko_bug(env, git_gecko, git_wpt, hg_gecko_upstream, upstream_gecko_commit) # 'Merge' this upstream PR pr = env.gh_wpt.get_pull(sync.pr) pr["base"] = {"sha": git_wpt_upstream.head.commit.hexsha} pr["user"]["login"] = "******" with SyncLock.for_process(sync.process_name) as upstream_sync_lock: with sync.as_mut(upstream_sync_lock): sync.push_commits() git_wpt_upstream.branches['gecko/1234'].checkout() extra_commit = git_commit(git_wpt_upstream, "Fixed pr before merge", {"EXTRA": "This fixes it"}) git_wpt_upstream.branches.master.checkout() assert str(git_wpt_upstream.active_branch) == "master" git_wpt_upstream.git.merge('gecko/1234') # TODO avoid hardcoding? # Create a ref on the upstream to simulate the pr than GH would setup git_wpt_upstream.create_head( 'pr/%d' % pr['number'], commit=git_wpt_upstream.refs['gecko/1234'].commit.hexsha) git_wpt.remotes.origin.fetch() pr['merge_commit_sha'] = str(git_wpt_upstream.active_branch.commit.hexsha) env.gh_wpt.commit_prs[pr['merge_commit_sha']] = pr['number'] landing_sync = landing.update_landing(git_gecko, git_wpt, include_incomplete=True) commits = landing_sync.gecko_commits._commits assert len(commits) == 2 # Check that the first commit is our "fix commit" which didn't come from Gecko assert commits[0].metadata['wpt-commits'] == extra_commit.hexsha # Check that the other commit is the bot's push commit assert commits[1].metadata['MANUAL PUSH'] == "wpt sync bot"
def test_download_logs_after_retriggers_complete(git_gecko, git_wpt, try_push, mock_tasks, env): # > 80% of retriggered "foo" tasks pass, so we consider the "foo" failure intermittent mock_tasks = Mock( return_value=mock_tasks(failed=["foo", "foo", "bar"], completed=[ "bar", "bar", "bar" "baz", "boo", "foo", "foo", "foo", "foo", "foo", "foobar", "foobar", "foobar" ])) with patch.object(tc.TaskGroup, "tasks", property(mock_tasks)): sync = landing.update_landing(git_gecko, git_wpt) try_push.download_logs = Mock(return_value=[]) try_push["stability"] = True landing.try_push_complete(git_gecko, git_wpt, try_push, sync) try_push.download_logs.assert_called_with(raw=False, report=True, exclude=["foo"]) assert sync.status == "open" assert try_push.status == "complete"
def test_land_try(env, git_gecko, git_wpt, git_wpt_upstream, pull_request, set_pr_status, hg_gecko_try, mock_mach): pr = pull_request([("Test commit", { "README": "example_change", "LICENSE": "Some change" })]) head_rev = pr._commits[0]["sha"] trypush.Mach = mock_mach downstream.new_wpt_pr(git_gecko, git_wpt, pr) sync = set_pr_status(pr, "success") git_wpt_upstream.head.commit = head_rev git_wpt.remotes.origin.fetch() landing.wpt_push(git_gecko, git_wpt, [head_rev], create_missing=False) sync.data["force-metadata-ready"] = True tree.is_open = lambda x: True landing_sync = landing.update_landing(git_gecko, git_wpt) assert landing_sync is not None worktree = landing_sync.gecko_worktree.get() # Check that files we shouldn't move aren't assert not os.path.exists( os.path.join(worktree.working_dir, env.config["gecko"]["path"]["wpt"], ".git")) with open( os.path.join(worktree.working_dir, env.config["gecko"]["path"]["wpt"], "LICENSE")) as f: assert f.read() == "Initial license\n" try_push = sync.latest_try_push assert try_push is not None assert try_push.status == "open" assert try_push.stability is False mach_command = mock_mach.get_log()[-1] assert mach_command["command"] == "mach" assert mach_command["args"] == ("try", "fuzzy", "-q", "web-platform-tests !pgo !ccov !msvc", "--artifact")
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