All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: git@vger.kernel.org, mhagger@alum.mit.edu, jrnieder@gmail.com,
	ronniesahlberg@gmail.com
Subject: Re: [PATCH 5/5] t5543-atomic-push.sh: add basic tests for atomic pushes
Date: Mon, 15 Dec 2014 14:29:47 -0800	[thread overview]
Message-ID: <xmqq4mswczs4.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1418673368-20785-6-git-send-email-sbeller@google.com> (Stefan Beller's message of "Mon, 15 Dec 2014 11:56:08 -0800")

Stefan Beller <sbeller@google.com> writes:

> This adds tests for the atomic push option.
> The first four tests check if the atomic option works in
> good conditions and the last three patches check if the atomic
> option prevents any change to be pushed if just one ref cannot
> be updated.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> Notes:
>     Originally Ronnie had a similar patch prepared. But as I added
>     more tests and cleaned up the existing tests (e.g. use test_commit
>     instead of "echo one >file && gitadd file && git commit -a -m 'one'",
>     removal of dead code), the file has changed so much that I'd rather
>     take ownership.
>
>  t/t5543-atomic-push.sh | 185 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 185 insertions(+)
>  create mode 100755 t/t5543-atomic-push.sh
>
> diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh
> new file mode 100755
> index 0000000..6cbedc5
> --- /dev/null
> +++ b/t/t5543-atomic-push.sh
> @@ -0,0 +1,185 @@
> +#!/bin/sh
> +
> +test_description='pushing to a repository using the atomic push option'
> +
> +. ./test-lib.sh
> +
> +D=`pwd`

$(pwd)???

> +mk_repo_pair () {
> +	rm -rf workbench upstream thirdparty &&
> +	mkdir upstream &&
> +	(
> +		cd upstream &&
> +		git init --bare #&&
> +		#git config receive.denyCurrentBranch warn

Please drop unused comments; they are distracting.

> +	) &&
> +	mkdir workbench &&
> +	(
> +		cd workbench &&
> +		git init &&
> +		git remote add up ../upstream
> +	)
> +}

Hmph.  Shouldn't you be using test_create_repo to create these, so
that templates are used from the build (not install) location, and
their hooks are disabled?

> +test_push_failed () {

Does that mean "test_push_must_fail"?

> +	workbench_master=$(cd workbench && git show-ref -s --verify refs/heads/master) &&
> +	upstream_master=$(cd upstream && git show-ref -s --verify refs/heads/master) &&
> +	test "$workbench_master" != "$upstream_master" &&
> +
> +	workbench_second=$(cd workbench && git show-ref -s --verify refs/heads/second) &&
> +	upstream_second=$(cd upstream && git show-ref -s --verify refs/heads/second) &&
> +	test "$workbench_second" != "$upstream_second"

So the tests that use this helper always try to update master and
second?  Is "they are different" the only thing that matters?  Or
should you be verifying "They are left as the same value they used
to have before the attempted push that must have failed"?

It might be a good time to use "-C" option, e.g. "git -C workbench show-ref ...",
a bit more in our tests.

> +}
> +
> +test_push_succeeded () {
> +	workbench_master=$(cd workbench && git show-ref -s --verify refs/heads/master) &&
> +	upstream_master=$(cd upstream && git show-ref -s --verify refs/heads/master) &&
> +	test "$workbench_master" = "$upstream_master"

Broken &&-chain?

> +
> +	workbench_second=$(cd workbench && git show-ref -s --verify refs/heads/second) &&
> +	upstream_second=$(cd upstream && git show-ref -s --verify refs/heads/second) &&
> +	test "$workbench_second" = "$upstream_second"
> +}
> +
> +test_expect_success 'atomic push works for a single branch' '
> +	mk_repo_pair &&
> +	(
> +		cd workbench &&
> +		test_commit one &&
> +		git push --mirror up &&
> +		test_commit two &&
> +		git push --atomic-push --mirror up
> +	) &&
> +	workbench_master=$(cd workbench && git show-ref -s --verify refs/heads/master) &&
> +	upstream_master=$(cd upstream && git show-ref -s --verify refs/heads/master) &&
> +	test "$workbench_master" = "$upstream_master"

Hmph.  It is a shame that the nice helper you created cannot be used
here.

> +'
> +
> +test_expect_success 'atomic push works for two branches' '
> +	mk_repo_pair &&
> +	(
> +		cd workbench &&
> +		test_commit one &&
> +		git branch second &&
> +		git push --mirror up &&
> +		test_commit two &&
> +		git checkout second &&
> +		test_commit three &&
> +		git push --atomic-push --mirror up
> +	) &&
> +	test_push_succeeded
> +'

OK.

> +test_expect_success 'atomic push works in combination with --mirror' '
> +	mk_repo_pair &&
> +	ls workbench &&

Debugging?

> +	(
> +		cd workbench &&
> +		test_commit one &&
> +		git checkout -b second &&
> +		test_commit two &&
> +		git push --atomic-push --mirror up

It is not wrong per-se, but haven't you already tested in
combination with --mirror in the previous test?

> +	) &&
> +	test_push_succeeded
> +'
> +
> +test_expect_success 'atomic push works in combination with --force' '
> +	mk_repo_pair &&
> +	(
> +		cd workbench &&
> +		test_commit one &&
> +		git checkout -b second &&
> +		test_commit two &&
> +		test_commit three &&
> +		test_commit four &&
> +		git push --mirror up &&
> +		git reset --hard HEAD^ &&
> +		git push --force --atomic-push up master second
> +	) &&
> +	test_push_succeeded
> +'

OK.

> +# set up two branches where master can be pushed but second can not
> +# (non-fast-forward). Since second can not be pushed the whole operation
> +# will fail and leave master untouched.
> +test_expect_success 'atomic push fails if one branch fails locally' '
> +	mk_repo_pair &&
> +	(
> +		cd workbench &&
> +		test_commit one &&
> +		git checkout -b second master &&
> +		test_commit two &&
> +		test_commit three &&
> +		test_commit four &&
> +		git push --mirror up

Broken &&-chain.

> +		git reset --hard HEAD~2 &&
> +		git checkout master &&
> +		test_commit five &&
> +		! git push --atomic-push --all up

test_must_fail?

> +	) &&
> +	test_push_failed

You not only want to see master and second in upstream different from 
those in workbench, but they point at specific commits that the previous
mirror push updated to.

Instead of test_push_failed / test_push_succeeded, how about a
single helper that takes the two commit object names you expect
these two branches point at?  E.g.

	check_branches upstream master HEAD@{2} second HEAD~

(I am probably miscounting HEAD@{$offset} here; this is for
illustration only) that roughly does

	check_branches () {
		target=$1
                shift
                while test $# -ne 0
                do
			git -C "$target" rev-parse --verify "refs/heads/$1" >actual &&
			git rev-parse "$2" >expect &&
			test_cmp expect actual || return 1
			shift
                        shift
		done
	}

or something like that?

> +test_expect_success 'atomic push fails if one branch fails remotely' '
> +	# prepare the repo
> +	mk_repo_pair &&
> +	(
> +		cd workbench &&
> +		test_commit one &&
> +		git checkout -b second master &&
> +		test_commit two &&
> +		git push --mirror up
> +	) &&
> +	# a third party modifies the server side:
> +	(
> +		git clone upstream thirdparty &&
> +		cd thirdparty
> +		git checkout second
> +		test_commit unrelated_changes &&
> +		git push origin second
> +	) &&
> +	# see if we can now push both branches.
> +	(
> +		cd workbench &&
> +		git checkout master &&
> +		test_commit three &&
> +		git checkout second &&
> +		test_commit four &&
> +		! git push --atomic-push up master second
> +	) &&
> +	test_push_failed
> +'

What's the value of this test?  Isn't it a non-fast-forward check
you already tested in the previous one?

> +test_expect_success 'atomic push fails if one tag fails remotely' '
> +	# prepare the repo
> +	mk_repo_pair &&
> +	(
> +		cd workbench &&
> +		test_commit one &&
> +		git checkout -b second master &&
> +		test_commit two &&
> +		git push --mirror up
> +	) &&
> +	# a third party modifies the server side:
> +	(
> +		git clone upstream thirdparty &&
> +		cd thirdparty
> +		git checkout second
> +		git tag test_tag &&
> +		git push --tags origin second
> +	) &&

Broken &&-chain aside, you do not need thirdparty.  Doing the "git
tag" inside upstream itself should suffice.

> +	# see if we can now push both branches.
> +	(
> +		cd workbench &&
> +		git checkout master &&
> +		test_commit three &&
> +		git checkout second &&
> +		test_commit four &&
> +		git tag test_tag &&
> +		! git push --tags --atomic-push up master second

test_must_fail?

> +	) &&
> +	test_push_failed
> +'

One more failure mode you would want to check is what if "update"
hook in the receiving repository rejected one update (but not the
other).  Something along the lines of:

	... setup ...
	git -C workbench push up &&
        write_script upstream/hooks/update <<-\EOF &&
	# only allow update to master from now on
        test "$1" = "refs/heads/master"
        EOF
        ... further update to master and second ...
        test_must_fail git -C workbench push up
	check_branches upstream master ... second ...


perhaps?

  reply	other threads:[~2014-12-15 22:29 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-15 19:56 [PATCH 0/5] Add a flag to push atomically Stefan Beller
2014-12-15 19:56 ` [PATCH 1/5] receive-pack.c: add protocol support to negotiate atomic-push Stefan Beller
2014-12-15 20:53   ` Junio C Hamano
2014-12-15 22:30     ` Stefan Beller
2014-12-15 19:56 ` [PATCH 2/5] send-pack.c: add an --atomic-push command line argument Stefan Beller
2014-12-15 21:01   ` Junio C Hamano
2014-12-15 19:56 ` [PATCH 3/5] receive-pack.c: use a single ref_transaction for atomic pushes Stefan Beller
2014-12-15 21:37   ` Junio C Hamano
2014-12-15 19:56 ` [PATCH 4/5] push.c: add an --atomic-push argument Stefan Beller
2014-12-15 21:50   ` Junio C Hamano
2014-12-15 19:56 ` [PATCH 5/5] t5543-atomic-push.sh: add basic tests for atomic pushes Stefan Beller
2014-12-15 22:29   ` Junio C Hamano [this message]
2014-12-15 22:33 ` [PATCH 0/5] Add a flag to push atomically Junio C Hamano
2014-12-16 18:49   ` [PATCHv2 1/6] receive-pack.c: add protocol support to negotiate atomic-push Stefan Beller
2014-12-16 18:49     ` [PATCHv2 2/6] send-pack: Invert the return value of ref_update_to_be_sent Stefan Beller
2014-12-16 19:14       ` Junio C Hamano
2014-12-16 18:49     ` [PATCHv2 3/6] send-pack.c: add --atomic command line argument Stefan Beller
2014-12-16 19:31       ` Junio C Hamano
2014-12-16 18:49     ` [PATCHv2 4/6] receive-pack.c: use a single ref_transaction for atomic pushes Stefan Beller
2014-12-16 19:29       ` Eric Sunshine
2014-12-16 20:30         ` Eric Sunshine
2014-12-16 19:35       ` Junio C Hamano
2014-12-16 18:49     ` [PATCHv2 5/6] push.c: add an --atomic-push argument Stefan Beller
2014-12-16 19:33       ` Eric Sunshine
2014-12-16 20:43         ` Junio C Hamano
2014-12-16 19:36       ` Junio C Hamano
2014-12-16 18:49     ` [PATCHv2 6/6] t5543-atomic-push.sh: add basic tests for atomic pushes Stefan Beller
2014-12-16 19:14       ` [PATCH] receive-pack: refuse all commands if one fails in atomic mode Stefan Beller
2014-12-16 20:32         ` Junio C Hamano
2014-12-16 19:37       ` [PATCHv2 6/6] t5543-atomic-push.sh: add basic tests for atomic pushes Eric Sunshine
2014-12-16 19:46       ` Junio C Hamano
2014-12-16 19:57         ` Stefan Beller
2014-12-16 20:46           ` Junio C Hamano
2014-12-16 20:51             ` Stefan Beller
2014-12-16 20:30       ` Junio C Hamano
2014-12-16 20:36         ` Stefan Beller
2014-12-16 19:05     ` [PATCHv2 1/6] receive-pack.c: add protocol support to negotiate atomic-push Junio C Hamano
2014-12-17 18:32   ` [PATCHv3 0/6] atomic pushes Stefan Beller
2014-12-17 18:32     ` [PATCHv3 1/6] receive-pack.c: add protocol support to negotiate atomic Stefan Beller
2014-12-19  1:05       ` Eric Sunshine
2014-12-17 18:32     ` [PATCHv3 2/6] send-pack: Rename ref_update_to_be_sent to check_to_send_update Stefan Beller
2014-12-17 22:53       ` Junio C Hamano
2014-12-17 18:32     ` [PATCHv3 3/6] send-pack.c: add --atomic command line argument Stefan Beller
2014-12-17 23:14       ` Junio C Hamano
2014-12-19  1:22       ` Eric Sunshine
2014-12-17 18:32     ` [PATCHv3 4/6] receive-pack.c: use a single ref_transaction for atomic pushes Stefan Beller
2014-12-17 23:26       ` Junio C Hamano
2014-12-17 23:58         ` Stefan Beller
2014-12-18 17:02           ` Junio C Hamano
2014-12-18 17:45             ` [PATCHv4 " Stefan Beller
2014-12-18 22:26               ` Eric Sunshine
2014-12-19  0:22                 ` [PATCHv5 " Stefan Beller
2014-12-19 10:14                   ` Eric Sunshine
2014-12-17 18:32     ` [PATCHv3 5/6] push.c: add an --atomic argument Stefan Beller
2014-12-19  1:29       ` Eric Sunshine
2014-12-17 18:32     ` [PATCHv3 6/6] t5543-atomic-push.sh: add basic tests for atomic pushes Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4mswczs4.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=mhagger@alum.mit.edu \
    --cc=ronniesahlberg@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.