Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: infra/services/gnumbd/test/gnumbd_smoketests.py

Issue 355153002: Refactor infra git libs and testing. (Closed) Base URL: https://chromium.googlesource.com/infra/infra@fake_testing_support
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: infra/services/gnumbd/test/gnumbd_smoketests.py
diff --git a/infra/services/gnumbd/test/gnumbd_smoketests.py b/infra/services/gnumbd/test/gnumbd_smoketests.py
deleted file mode 100644
index ee2c3953897ccd8e87414883c04fb1a990ba3af5..0000000000000000000000000000000000000000
--- a/infra/services/gnumbd/test/gnumbd_smoketests.py
+++ /dev/null
@@ -1,507 +0,0 @@
-# Copyright 2014 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import collections
-
-from infra.services.gnumbd import inner_loop as gnumbd
-content_of = gnumbd.content_of
-
-REAL = 'refs/heads/master'
-PEND = 'refs/pending/heads/master'
-PEND_TAG = 'refs/pending-tags/heads/master'
-
-BRANCH = 'refs/branch-heads/cool_branch'
-BRANCH_PEND = 'refs/pending/branch-heads/cool_branch'
-BRANCH_TAG = 'refs/pending-tags/branch-heads/cool_branch'
-
-
-GNUMBD_TESTS = {}
-def gnumbd_test(f):
- GNUMBD_TESTS[f.__name__] = f
- return f
-
-
-# Error cases
-@gnumbd_test
-def no_real_ref(origin, _local, _config_ref, RUN, CHECKPOINT):
- origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('One commit in origin')
- RUN()
- CHECKPOINT('Origin should not have changed')
-
-
-@gnumbd_test
-def no_pending_tag(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- origin[PEND].update_to(base_commit)
- origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('Two commits in origin')
- RUN()
- CHECKPOINT('Origin should not have changed')
-
-
-@gnumbd_test
-def bad_position_footer(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit(
- 'Base commit', footers={gnumbd.COMMIT_POSITION: ['BlobbyGumpus!']})
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('Bad master commit footer')
- RUN()
- CHECKPOINT('Should be the same')
- assert origin[REAL].commit == base_commit
-
-
-@gnumbd_test
-def bad_svn_footer(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit(
- 'Base commit', footers={gnumbd.GIT_SVN_ID: ['BlobbyGumpus!']})
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('Bad master commit footer')
- RUN()
- CHECKPOINT('Should be the same')
- assert origin[REAL].commit == base_commit
-
-
-@gnumbd_test
-def no_position_footer(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit(
- 'Base commit', footers={'Sup': ['Not a footer']})
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('Master has no position footer')
- RUN()
- CHECKPOINT('Should be the same')
- assert origin[REAL].commit == base_commit
-
-
-@gnumbd_test
-def merge_commits_fail(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- o_commit = origin['refs/heads/other'].synthesize_commit('Incoming merge!', 20)
- m_commit = base_commit.alter(
- parents=(base_commit.hsh, o_commit.hsh),
- message_lines=['Two for one!'],
- footers={k: None for k in base_commit.data.footers}
- )
-
- origin[PEND].update_to(m_commit)
- origin[PEND].synthesize_commit('Hello world')
-
- CHECKPOINT('The setup.')
- RUN()
- CHECKPOINT('Should be the same')
-
-
-@gnumbd_test
-def manual_merge_commits_ok(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
-
- o_commit = origin['refs/heads/other'].synthesize_commit('Incoming merge!', 20)
- footers = {k: None for k in base_commit.data.footers}
- footers[gnumbd.COMMIT_POSITION] = ['refs/heads/master@{#101}']
-
- m_commit = base_commit.alter(
- parents=(base_commit.hsh, o_commit.hsh),
- message_lines=['Two for one!'],
- footers=footers
- )
- origin[REAL].update_to(m_commit)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(m_commit)
-
- origin[PEND].synthesize_commit('Hello world')
-
- CHECKPOINT('The setup.')
- RUN()
- CHECKPOINT('Hello world landed w/o a hitch')
-
-
-@gnumbd_test
-def no_number_on_parent(origin, local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base without number')
- user_commit = origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('One commit in origin')
- RUN()
- CHECKPOINT('Should still only have 1 commit')
- assert local[PEND].commit == user_commit
- assert local[REAL].commit == base_commit
-
-
-# Normal cases
-@gnumbd_test
-def incoming_svn_id_drops(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100, svn=True)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- user_commit = origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('Two commits in origin')
- RUN()
- CHECKPOINT('Hello world should be 101')
- assert content_of(origin[REAL].commit) == content_of(user_commit)
- assert origin[REAL].commit.parent == base_commit
-
-
-# pending > master == tag
-@gnumbd_test
-def normal_update(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- user_commit = origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('Two commits')
- RUN()
- CHECKPOINT('Hello world should be 101')
- assert content_of(origin[REAL].commit) == content_of(user_commit)
- assert origin[REAL].commit.parent == base_commit
-
-
-# master == pending == tag
-@gnumbd_test
-def steady_state(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- user_commit = origin[PEND].synthesize_commit('Hello world')
- RUN(include_log=False)
- CHECKPOINT('Hello world should be 101')
- RUN()
- CHECKPOINT('Hello world should still be 101')
- assert content_of(origin[REAL].commit) == content_of(user_commit)
- assert origin[REAL].commit.parent == base_commit
-
-
-# master == pending > tag
-@gnumbd_test
-def tag_lagging_no_actual(origin, _local, _config_ref, RUN, CHECKPOINT):
- origin[REAL].synthesize_commit('Root commit', 99)
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- user_commit = origin[PEND].synthesize_commit('Hello world')
-
- RUN(include_log=False)
- origin[PEND_TAG].update_to(origin[PEND_TAG].commit.parent.parent)
-
- CHECKPOINT('Tag on root (2 behind pend)')
- RUN()
- CHECKPOINT('Tag caught up')
- assert content_of(origin[REAL].commit) == content_of(user_commit)
- assert origin[REAL].commit.parent == base_commit
- assert origin[PEND_TAG].commit == origin[PEND].commit
-
-
-# pending > master > tag
-@gnumbd_test
-def tag_lagging(origin, _local, _config_ref, RUN, CHECKPOINT):
- origin[REAL].synthesize_commit('Root commit', 99)
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[PEND].synthesize_commit('Hello world')
-
- RUN(include_log=False)
- landed_commit = origin[REAL].commit
-
- origin[PEND_TAG].update_to(origin[PEND_TAG].commit.parent.parent)
- user_commit = origin[PEND].synthesize_commit('New commit')
-
- CHECKPOINT('Tag on root (3 behind pend). Real 1 behind pend')
- RUN()
- CHECKPOINT('Tag + pending caught up')
- assert content_of(origin[REAL].commit) == content_of(user_commit)
- assert origin[REAL].commit.parent == landed_commit
- assert origin[PEND_TAG].commit == origin[PEND].commit
-
-
-@gnumbd_test
-def multi_pending(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- user_commit1 = origin[PEND].synthesize_commit('Hello world')
- user_commit2 = origin[PEND].synthesize_commit('Cat food')
- CHECKPOINT('Two pending commits')
- RUN()
- CHECKPOINT('And now they\'re on master')
- assert content_of(origin[REAL].commit.parent) == content_of(user_commit1)
- assert content_of(origin[REAL].commit) == content_of(user_commit2)
- assert origin[REAL].commit.parent.parent == base_commit
-
-
-# Inconsistency
-
-# tag > pending
-# Implicitly covers:
-# * master > tag > pending
-# * tag > pending > master
-# * tag > master > pending
-# * tag > pending == master
-@gnumbd_test
-def master_tag_ahead_pending(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[PEND].synthesize_commit('Hello world')
- RUN(include_log=False)
-
- origin[PEND].update_to(base_commit)
- CHECKPOINT('Master and tag ahead of pending')
- RUN()
- CHECKPOINT('Should see errors and no change')
-
-
-# pending > tag > master
-@gnumbd_test
-def normal_with_master_lag(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[PEND].synthesize_commit('Hello world')
- RUN(include_log=False)
-
- # master moves back
- origin[REAL].update_to(base_commit)
-
- # pending gets a new commit
- origin[PEND].synthesize_commit('New pending')
-
- CHECKPOINT('Master is behind, pending is ahead of tag')
- RUN()
- CHECKPOINT('Should see errors and no change')
-
- # fix by rewinding tag
- origin[PEND_TAG].update_to(origin[PEND_TAG].commit.parent)
- CHECKPOINT('Fix by rewinding tag')
- RUN()
- CHECKPOINT('All better')
-
-
-@gnumbd_test
-def master_ahead_tag_ahead_pending(origin, _local, _config_ref, RUN,
- CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[REAL].synthesize_commit('Directly landed commit!')
- origin[PEND_TAG].synthesize_commit('Tag ahead of pending')
-
- CHECKPOINT('Master and tag have diverged, pend lags')
- RUN()
- CHECKPOINT('Should have errored and nothing changed')
-
-
-# master > pending == tag
-@gnumbd_test
-def master_ahead(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- base_commit = origin[REAL].synthesize_commit('Directly landed commit!')
-
- CHECKPOINT('Master contains a commit whose content isn\'t in pending')
- RUN()
- CHECKPOINT('Should have errored and nothing changed')
- assert origin[REAL].commit == base_commit
-
-
-# pending == tag > master
-@gnumbd_test
-def master_behind(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- user_commit = origin[PEND].synthesize_commit('Hello world')
- origin[PEND_TAG].update_to(user_commit)
- CHECKPOINT('Master should have new commit but does not')
- RUN()
- CHECKPOINT('Error and no change')
-
-
-# master > pending > tag
-@gnumbd_test
-def master_mismatch_and_pend(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
- origin[PEND].synthesize_commit('Hello world')
-
- base_commit = origin[REAL].synthesize_commit('Directly landed commit!')
-
- CHECKPOINT('Master contains a commit whose content isn\'t in pending')
- RUN()
- CHECKPOINT('Should have errored and nothing changed')
- assert origin[REAL].commit == base_commit
-
-
-# Branching
-@gnumbd_test
-def branch(origin, _local, config_ref, RUN, CHECKPOINT):
- new_globs = config_ref['enabled_refglobs'] + ['refs/branch-heads/*']
- config_ref.update(enabled_refglobs=new_globs)
-
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[PEND].synthesize_commit('Hello world')
- CHECKPOINT('Pending commit', include_config=True)
- RUN()
- CHECKPOINT('And now it\'s on master', include_config=True)
-
- # Build a new branch
- for ref in (BRANCH, BRANCH_TAG, BRANCH_PEND):
- origin[ref].update_to(origin[REAL].commit)
-
- origin[BRANCH_PEND].synthesize_commit('Branch commit!')
- CHECKPOINT('New branch with pending', include_config=True)
- RUN()
- CHECKPOINT('Pending commit now on branch', include_config=True)
-
- origin[BRANCH_PEND].synthesize_commit('Another branch commit')
- CHECKPOINT('New pending commit for branch', include_config=True)
- RUN()
- CHECKPOINT('Second pending commit now on branch', include_config=True)
-
- assert origin[BRANCH].commit.data.footers[gnumbd.BRANCHED_FROM] == (
- '%s-%s' % (
- origin[REAL].commit.hsh,
- origin[REAL].commit.data.footers[gnumbd.COMMIT_POSITION][0]
- ),
- )
-
-
-@gnumbd_test
-def branch_from_branch(origin, _local, config_ref, RUN, CHECKPOINT):
- new_globs = config_ref['enabled_refglobs'] + ['refs/branch-heads/*']
- config_ref.update(enabled_refglobs=new_globs)
-
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- origin[PEND].synthesize_commit('Hello world')
- RUN(include_log=False)
-
- # Build a new branch
- for ref in (BRANCH, BRANCH_TAG, BRANCH_PEND):
- origin[ref].update_to(origin[REAL].commit)
-
- origin[BRANCH_PEND].synthesize_commit('Branch commit!')
- RUN(include_log=False)
-
- CHECKPOINT('Branch 1 in place', include_config=True)
-
- yo_branch = BRANCH+'_yo'
- yo_branch_tag = BRANCH_TAG+'_yo'
- yo_branch_pend = BRANCH_PEND+'_yo'
- for ref in (yo_branch, yo_branch_tag, yo_branch_pend):
- origin[ref].update_to(origin[BRANCH].commit)
-
- origin[yo_branch_pend].synthesize_commit('Super branchey commit')
- CHECKPOINT('New pending commit for branch', include_config=True)
- RUN()
- CHECKPOINT('Second pending commit now on branch', include_config=True)
-
- assert origin[yo_branch].commit.data.footers[gnumbd.BRANCHED_FROM] == (
- '%s-%s' % (
- origin[BRANCH].commit.hsh,
- origin[BRANCH].commit.data.footers[gnumbd.COMMIT_POSITION][0]
- ),
- '%s-%s' % (
- origin[REAL].commit.hsh,
- origin[REAL].commit.data.footers[gnumbd.COMMIT_POSITION][0]
- ),
- )
-
-
-# Extra footers
-@gnumbd_test
-def extra_user_footer(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- user_commit = origin[PEND].synthesize_commit(
- 'Hello world', footers=collections.OrderedDict([
- ('Change-Id', ['Icafebabe1cec6eadfeba']),
- ('Reviewed-by', [
- 'Cool Dudette 64 <cd64@example.com>',
- 'Epic Sky Troll <est@example.com>',
- ]),
- ('Tested-by', ['Lol JK <lol_jk@example.com>'])
- ]))
- CHECKPOINT('The setup...')
- RUN()
- CHECKPOINT('The new footers should appear after the current ones')
- assert content_of(origin[REAL].commit) == content_of(user_commit)
- assert origin[REAL].commit.parent == base_commit
-
-
-@gnumbd_test
-def extra_user_footer_bad(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- user_commit = origin[PEND].synthesize_commit(
- 'Hello world', footers=collections.OrderedDict([
- ('Cr-Double-Secret', ['I can impersonate the daemon!']),
- ('git-svn-id', ['Well... this should never happen'])
- ]))
- CHECKPOINT('Two commits')
- RUN()
- CHECKPOINT('The bogus footers should be gone')
- assert content_of(origin[REAL].commit) == content_of(user_commit)
- assert origin[REAL].commit.data.footers == {
- gnumbd.COMMIT_POSITION: (gnumbd.FMT_COMMIT_POSITION(origin[REAL], 101),)
- }
-
-
-@gnumbd_test
-def enforce_commit_timestamps(origin, _local, _config_ref, RUN, CHECKPOINT):
- base_commit = origin[REAL].synthesize_commit('Base commit', 100)
- for ref in (PEND, PEND_TAG):
- origin[ref].update_to(base_commit)
-
- # cheat and rewind the TestClock
- origin._clock._time -= 100 # pylint: disable=W0212
-
- user_commit = origin[PEND].synthesize_commit('Hello world')
- assert (
- user_commit.data.committer.timestamp.secs <
- base_commit.data.committer.timestamp.secs
- )
-
- CHECKPOINT('%r has a timestamp behind %r' % (
- user_commit.hsh, base_commit.hsh), include_committer=True)
- RUN()
- CHECKPOINT('Presto! Timestamp is fixed', include_committer=True)
- assert content_of(origin[REAL].commit) == content_of(user_commit)
- assert origin[REAL].commit.parent == base_commit
- assert (
- origin[REAL].commit.data.committer.timestamp.secs >
- origin[REAL].commit.parent.data.committer.timestamp.secs
- )

Powered by Google App Engine
This is Rietveld 408576698