Skip to content

Commit 38c837b

Browse files
committed
address review: alphabetize flags, add readme docs, add e2e tests
1 parent 6a3f31b commit 38c837b

3 files changed

Lines changed: 64 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,17 @@ OPTIONS
365365
Enable the pprof debug endpoints on git-sync's HTTP endpoint at
366366
/debug/pprof. Requires --http-bind to be specified.
367367
368+
--init-period <duration>, $GITSYNC_INIT_PERIOD
369+
How long to wait between sync attempts until the first successful
370+
sync. This must be at least 10ms if set. If not specified, the
371+
value of --period is used for initial sync attempts as well.
372+
373+
--init-timeout <duration>, $GITSYNC_INIT_TIMEOUT
374+
The maximum time allowed for the initial sync to succeed. If the
375+
first successful sync does not occur within this duration, git-sync
376+
will exit with an error. If not specified, there is no timeout and
377+
git-sync will retry until --max-failures is reached.
378+
368379
--link <string>, $GITSYNC_LINK
369380
The path to at which to create a symlink which points to the
370381
current git directory, at the currently synced hash. This may be

‎main.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ func main() {
183183
flErrorFile := pflag.String("error-file",
184184
envString("", "GITSYNC_ERROR_FILE", "GIT_SYNC_ERROR_FILE"),
185185
"the path (absolute or relative to --root) to an optional file into which errors will be written (defaults to disabled)")
186-
flPeriod := pflag.Duration("period",
187-
envDuration(10*time.Second, "GITSYNC_PERIOD", "GIT_SYNC_PERIOD"),
188-
"how long to wait between syncs, must be >= 10ms; --wait overrides this")
189186
flInitPeriod := pflag.Duration("init-period",
190187
envDuration(0, "GITSYNC_INIT_PERIOD"),
191188
"how long to wait between sync attempts until the first success, must be >= 10ms if set; if unset, --period is used")
192189
flInitTimeout := pflag.Duration("init-timeout",
193190
envDuration(0, "GITSYNC_INIT_TIMEOUT"),
194191
"the max time allowed for the initial sync to succeed; if unset, there is no timeout (retries forever until --max-failures)")
192+
flPeriod := pflag.Duration("period",
193+
envDuration(10*time.Second, "GITSYNC_PERIOD", "GIT_SYNC_PERIOD"),
194+
"how long to wait between syncs, must be >= 10ms; --wait overrides this")
195195
flSyncTimeout := pflag.Duration("sync-timeout",
196196
envDuration(120*time.Second, "GITSYNC_SYNC_TIMEOUT", "GIT_SYNC_SYNC_TIMEOUT"),
197197
"the total time allowed for one complete sync, must be >= 10ms; --timeout overrides this")

‎test_e2e.sh‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,6 +3683,56 @@ function e2e::exechook_git_archive() {
36833683
assert_tgz_archive "$ROOT/link/archive.tgz"
36843684
}
36853685

3686+
##############################################
3687+
# Test init-period uses faster interval for initial sync
3688+
##############################################
3689+
function e2e::init_period_faster_initial_sync() {
3690+
# First sync
3691+
echo "${FUNCNAME[0]} 1" > "$REPO/file"
3692+
git -C "$REPO" commit -qam "${FUNCNAME[0]} 1"
3693+
3694+
GIT_SYNC \
3695+
--period=100s \
3696+
--init-period=100ms \
3697+
--repo="file://$REPO" \
3698+
--root="$ROOT" \
3699+
--link="link" \
3700+
&
3701+
# With init-period=100ms, sync should happen quickly even though
3702+
# period=100s. If init-period were not working, this would time out.
3703+
wait_for_sync "${MAXWAIT}"
3704+
assert_link_exists "$ROOT/link"
3705+
assert_file_exists "$ROOT/link/file"
3706+
assert_file_eq "$ROOT/link/file" "${FUNCNAME[0]} 1"
3707+
assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1
3708+
3709+
# After initial sync, period should switch to the normal 100s.
3710+
# Make a new commit and verify it does NOT sync quickly (because
3711+
# we're now using the slow period).
3712+
echo "${FUNCNAME[0]} 2" > "$REPO/file"
3713+
git -C "$REPO" commit -qam "${FUNCNAME[0]} 2"
3714+
# Wait a bit - should NOT have synced since normal period is 100s
3715+
sleep 3
3716+
assert_file_eq "$ROOT/link/file" "${FUNCNAME[0]} 1"
3717+
assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1
3718+
}
3719+
3720+
##############################################
3721+
# Test init-timeout exits on timeout
3722+
##############################################
3723+
function e2e::init_timeout_expires() {
3724+
assert_fail \
3725+
GIT_SYNC \
3726+
--git="/$SLOW_GIT_FETCH" \
3727+
--period=100ms \
3728+
--init-timeout=1s \
3729+
--max-failures=-1 \
3730+
--repo="file://$REPO" \
3731+
--root="$ROOT" \
3732+
--link="link"
3733+
assert_file_absent "$ROOT/link/file"
3734+
}
3735+
36863736
#
36873737
# main
36883738
#

0 commit comments

Comments
 (0)