Skip to content

Commit

Permalink
#625 Git index - settling on pauses when testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Dec 21, 2018
1 parent 27d0dd5 commit 73650bb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
Expand Up @@ -180,6 +180,13 @@ interface GitService : SCMService {
/**
* Collects and stores the [IndexableGitCommit]s for all builds of a branch.
*/
fun collectIndexableGitCommitForBranch(branch: Branch)

/**
* Collects and stores the [IndexableGitCommit]s for all builds of a branch.
*
* This is the optimized version for jobs running in the background.
*/
fun collectIndexableGitCommitForBranch(branch: Branch,
client: GitRepositoryClient,
config: GitBranchConfiguration,
Expand Down
Expand Up @@ -830,6 +830,24 @@ class GitServiceImpl(
)
}

override fun collectIndexableGitCommitForBranch(branch: Branch) {
val project = branch.project
val projectConfiguration = getProjectConfiguration(project)
if (projectConfiguration != null) {
val client = gitRepositoryClientFactory.getClient(projectConfiguration.gitRepository)
val branchConfiguration = getBranchConfiguration(branch)
if (branchConfiguration != null) {
collectIndexableGitCommitForBranch(
branch,
client,
branchConfiguration,
true,
JobRunListener.logger(logger)
)
}
}
}

override fun collectIndexableGitCommitForBranch(
branch: Branch,
client: GitRepositoryClient,
Expand Down
Expand Up @@ -11,7 +11,7 @@ class GitCommitInfoGraphQLIT : AbstractGitTestSupport() {
@Test
fun `Getting commit info`() {
createRepo {
sequence(
sequenceWithPauses(
(1..3),
"release/2.0",
4,
Expand Down
Expand Up @@ -19,9 +19,9 @@ class GitIssueSearchIT : AbstractGitTestSupport() {
@Test
fun `Issue search on one branch`() {
createRepo {
commit(1, "#1 First commit")
commit(2, "#2 Second commit")
commit(3, "#2 Third commit")
commit(1, "#1 First commit", pause = true)
commit(2, "#2 Second commit", pause = true)
commit(3, "#2 Third commit", pause = true)
commit(4, "#1 Fourth commit")
} and { repo, _ ->
project {
Expand All @@ -33,6 +33,8 @@ class GitIssueSearchIT : AbstractGitTestSupport() {
build(repo.commitLookup("#1 First commit"))
build(repo.commitLookup("#2 Third commit"))
build(repo.commitLookup("#1 Fourth commit"))
// Makes sure to index the branch builds commits
gitService.collectIndexableGitCommitForBranch(this)
}
// Looks for an issue
val info = asUserWithView(this).call {
Expand Down Expand Up @@ -76,11 +78,11 @@ class GitIssueSearchIT : AbstractGitTestSupport() {
@Test
fun `Issue search between two branches`() {
createRepo {
val commit1 = commit(1, "Commit #2 one")
val commit1 = commit(1, "Commit #2 one", pause = true)
git("checkout", "-b", "1.0")
val commit2 = commit(2, "Commit #2 two")
val commit2 = commit(2, "Commit #2 two", pause = true)
git("checkout", "master")
val commit3 = commit(3, "Commit #2 three")
val commit3 = commit(3, "Commit #2 three", pause = true)
// Commits index
mapOf(
1 to commit1,
Expand Down
Expand Up @@ -5,6 +5,7 @@ import net.nemerosa.ontrack.git.GitRepository
import net.nemerosa.ontrack.git.GitRepositoryClient
import org.apache.commons.io.FileUtils
import java.io.File
import java.lang.Thread.sleep

/**
* Utility class to deal with a Git repository.
Expand Down Expand Up @@ -107,12 +108,13 @@ class GitRepo(val dir: File) : AutoCloseable {
}

@JvmOverloads
fun commit(no: Any, message: String? = null): String {
fun commit(no: Any, message: String? = null, pause: Boolean = false): String {
val fileName = "file$no"
cmd("touch", fileName)
git("add", fileName)
val commitMessage = message ?: "Commit $no"
git("commit", "-m", commitMessage)
if (pause) sleep(1010)
return commitLookup(commitMessage, false)
}

Expand Down

0 comments on commit 73650bb

Please sign in to comment.