From 4b8c2e3582408bc58d97e9308a433fc917bcd4a3 Mon Sep 17 00:00:00 2001 From: Gustavo Galvao Avena Date: Fri, 3 Jan 2025 03:36:30 -0800 Subject: [PATCH] Extract more repo setup snippets into helper functions 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 --- .../library-git-submodules-repos-setup.sh | 48 +++++++++++++++++++ ...-import-and-merge-into-existing-megarepo.t | 10 +--- ...al-import-gitsubmodules-expand-recursive.t | 31 +----------- 3 files changed, 50 insertions(+), 39 deletions(-) diff --git a/eden/mononoke/tests/integration/cross_repo/library-git-submodules-repos-setup.sh b/eden/mononoke/tests/integration/cross_repo/library-git-submodules-repos-setup.sh index cfcd8b7028853..0b29cce97a757 100644 --- a/eden/mononoke/tests/integration/cross_repo/library-git-submodules-repos-setup.sh +++ b/eden/mononoke/tests/integration/cross_repo/library-git-submodules-repos-setup.sh @@ -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" @@ -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 + +} diff --git a/eden/mononoke/tests/integration/cross_repo/test-cross-repo-initial-import-and-merge-into-existing-megarepo.t b/eden/mononoke/tests/integration/cross_repo/test-cross-repo-initial-import-and-merge-into-existing-megarepo.t index 656c47b2047c7..1a2144a5d6b9d 100644 --- a/eden/mononoke/tests/integration/cross_repo/test-cross-repo-initial-import-and-merge-into-existing-megarepo.t +++ b/eden/mononoke/tests/integration/cross_repo/test-cross-repo-initial-import-and-merge-into-existing-megarepo.t @@ -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 diff --git a/eden/mononoke/tests/integration/cross_repo/test-cross-repo-initial-import-gitsubmodules-expand-recursive.t b/eden/mononoke/tests/integration/cross_repo/test-cross-repo-initial-import-gitsubmodules-expand-recursive.t index 751193d98fc6e..371970ad40f7a 100644 --- a/eden/mononoke/tests/integration/cross_repo/test-cross-repo-initial-import-gitsubmodules-expand-recursive.t +++ b/eden/mononoke/tests/integration/cross_repo/test-cross-repo-initial-import-gitsubmodules-expand-recursive.t @@ -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