Skip to content

Commit

Permalink
Extract more repo setup snippets into helper functions
Browse files Browse the repository at this point in the history
Summary:
## This stack
I want to make some improvements to the cross-repo integration tests that handle git submodules.

I created these over a year ago and since then, added many different kinds of tests, but the old ones (e.g. stripping submodules) are still a bit unorganized and are not necessarily reproducing prod behaviour like the newers ones (e.g. git pushrebase).

## This diff

Refactor more copy-pasta into common helper functions. This isn't perfect, but I believe it's better than before.

Reviewed By: andreacampi

Differential Revision: D67601364

fbshipit-source-id: 8a00539d836a2493fe98126e51579c7ddd2dc22b
  • Loading branch information
gustavoavena authored and facebook-github-bot committed Jan 3, 2025
1 parent 879890f commit 4b8c2e3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# shellcheck source=fbcode/eden/mononoke/tests/integration/library.sh
. "${TEST_FIXTURES}/library.sh"
. "${TEST_FIXTURES}/library-push-redirector.sh"
. "${TEST_FIXTURES}/cross_repo/library-git-submodules-config-setup.sh"
. "${TEST_FIXTURES}/cross_repo/library-git-submodules-helpers.sh"

Expand Down Expand Up @@ -475,3 +476,50 @@ CONFIG

cd "$orig_pwd" || exit
}

# Creates repos B and C, sets up repo A and merges it into the large repo.
function create_and_merge_submodule_repo {
# Setup git repos A, B and C
setup_git_repos_a_b_c

# Import all git repos into Mononoke
gitimport_repos_a_b_c

# Merge repo A into the large repo
merge_repo_a_to_large_repo
}

# - Runs `create_and_merge_submodule_repo`
# - Makes further changes to the repos to ensure they are synced properly
# - Sets up live sync
function setup_all_repos_for_test {
UPDATE_REPO_A=${UPDATE_REPO_A-1}

create_and_merge_submodule_repo

# Make changes to submodule and make sure they're synced properly
make_changes_to_git_repos_a_b_c

# Import the changes from the git repos B and C into their Mononoke repos
REPOID="$REPO_C_ID" QUIET_LOGGING_LOG_FILE="$TESTTMP/gitimport_repo_c.out" \
quiet gitimport "$GIT_REPO_C" --bypass-derived-data-backfilling \
--bypass-readonly --generate-bookmarks missing-for-commit "$GIT_REPO_C_HEAD"

REPOID="$REPO_B_ID" QUIET_LOGGING_LOG_FILE="$TESTTMP/gitimport_repo_b.out" \
quiet gitimport "$GIT_REPO_B" --bypass-derived-data-backfilling \
--bypass-readonly --generate-bookmarks missing-for-commit "$GIT_REPO_B_HEAD"

# Set up live forward syncer, which should sync all commits in small repo's (repo A)
# heads/master_bookmark bookmark to large repo's master_bookmark bookmark via pushrebase
touch "$TESTTMP/xreposync.out"
with_stripped_logs mononoke_x_repo_sync_forever "$SUBMODULE_REPO_ID" "$LARGE_REPO_ID"

# Import the changes from git repo A into its Mononoke repo. They should be automatically
# forward synced to the large repo
# TODO: generate or not bookmarks for SCS tests UPDATE_REPO_A
if [ "$UPDATE_REPO_A" != 0 ]; then
REPOID="$SUBMODULE_REPO_ID" with_stripped_logs gitimport "$GIT_REPO_A" --bypass-derived-data-backfilling \
--bypass-readonly --generate-bookmarks missing-for-commit "$GIT_REPO_A_HEAD" > "$TESTTMP/gitimport_output"
fi

}
Original file line number Diff line number Diff line change
Expand Up @@ -429,21 +429,13 @@ so they'll be dumped to files to keep this (already long) integration test short
$ REPOID="$REPO_B_ID" REPONAME="repo_b" \
> COMMIT_IDENTITY_SCHEME=3 setup_common_config "$REPOTYPE"

-- Setup git repos A, B and C
$ quiet setup_git_repos_a_b_c

-- Import all git repos into Mononoke
$ quiet gitimport_repos_a_b_c

-- Update the commit sync config
$ update_commit_sync_map_for_import_expanding_git_submodules
$ force_update_configerator


-- Merge repo A into the large repo
$ NOOP_CONFIG_VERSION_NAME="$SUBMODULE_NOOP_VERSION_NAME" \
> CONFIG_VERSION_NAME="$AFTER_SUBMODULE_REPO_VERSION_NAME" \
> MASTER_BOOKMARK="master_bookmark" quiet merge_repo_a_to_large_repo
> MASTER_BOOKMARK="master_bookmark" create_and_merge_submodule_repo

-- Set up live forward syncer, which should sync all commits in submodule repo's
-- heads/master bookmark to large repo's master bookmark via pushrebase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,11 @@ Run the x-repo with submodules setup
$ killandwait $MONONOKE_PID
$ start_and_wait_for_mononoke_server
-- Setup git repos A, B and C
$ quiet setup_git_repos_a_b_c
-- Import all git repos into Mononoke
$ quiet gitimport_repos_a_b_c
-- Merge repo A into the large repo
$ REPO_A_FOLDER="smallrepofolder1" quiet merge_repo_a_to_large_repo
-- Make changes to submodule and make sure they're synced properly
$ quiet make_changes_to_git_repos_a_b_c
$ REPO_A_FOLDER="smallrepofolder1" quiet setup_all_repos_for_test
$ mononoke_admin bookmarks -R "$SUBMODULE_REPO_NAME" list -S hg
heads/master_bookmark
-- Import the changes from the git repos B and C into their Mononoke repos
$ REPOID="$REPO_C_ID" QUIET_LOGGING_LOG_FILE="$TESTTMP/gitimport_repo_c.out" \
> quiet gitimport "$GIT_REPO_C" --bypass-derived-data-backfilling \
> --bypass-readonly --generate-bookmarks missing-for-commit "$GIT_REPO_C_HEAD"
$ REPOID="$REPO_B_ID" QUIET_LOGGING_LOG_FILE="$TESTTMP/gitimport_repo_b.out" \
> quiet gitimport "$GIT_REPO_B" --bypass-derived-data-backfilling \
> --bypass-readonly --generate-bookmarks missing-for-commit "$GIT_REPO_B_HEAD"
Set up live forward syncer, which should sync all commits in small repo's (repo A)
heads/master_bookmark bookmark to large repo's master_bookmark bookmark via pushrebase
$ touch $TESTTMP/xreposync.out
$ with_stripped_logs mononoke_x_repo_sync_forever "$SUBMODULE_REPO_ID" "$LARGE_REPO_ID"
-- Import the changes from git repo A into its Mononoke repo. They should be automatically
-- forward synced to the large repo
$ REPOID="$SUBMODULE_REPO_ID" with_stripped_logs gitimport "$GIT_REPO_A" --bypass-derived-data-backfilling \
> --bypass-readonly --generate-bookmarks missing-for-commit "$GIT_REPO_A_HEAD" > $TESTTMP/gitimport_output
$ QUIET_LOGGING_LOG_FILE="$TESTTMP/xrepo_sync_last_logs.out" with_stripped_logs wait_for_xrepo_sync 2
Expand Down

0 comments on commit 4b8c2e3

Please sign in to comment.