Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: repo_branch_test.go is flaky #28318

Closed
AdamMajer opened this issue Dec 1, 2023 · 6 comments · Fixed by #28348
Closed

test: repo_branch_test.go is flaky #28318

AdamMajer opened this issue Dec 1, 2023 · 6 comments · Fixed by #28348
Labels

Comments

@AdamMajer
Copy link
Contributor

Description

Every time I run this test, it seems to fail locally but succeed remotely.

2023/12/01 13:55:50 ...dules/git/command.go:275:Run() [E] git command is broken: /usr/bin/git -c protocol.version=2 -c credential.helper=, broken args: -test                                 
2023/12/01 13:55:50 ...dules/git/command.go:275:Run() [E] git command is broken: /usr/bin/git -c protocol.version=2 -c credential.helper=, broken args: --test                                
61ab7345a1a3bbc590068ccae37b8515cfc5843c                                                       
61ab7345a1a3bbc590068ccae37b8515cfc5843c                                                       
--- FAIL: TestRepository_GetBranches (0.00s)                                                                                                                                                  
    repo_branch_test.go:24:                                                                    
                Error Trace:    /home/adamm/work/alp/gitea/gitea/modules/git/repo_branch_test.go:24                                                                                           
                Error:          elements differ                                                
                                                                                               
                                extra elements in list A:               
                                ([]interface {}) (len=1) {                                     
                                 (string) (len=6) "master"                                     
                                }                                                              
                                                                                               
                                                                                               
                                extra elements in list B:                                      
                                ([]interface {}) (len=1) {                                     
                                 (string) (len=7) "branch1"                                    
                                }                                                              
                                                                                               
                                                                                               
                                listA:                                                         
                                ([]string) (len=2) {                                           
                                 (string) (len=6) "master",                                                                                                                                   
                                 (string) (len=7) "branch2"                                    
                                }                                                                                                                                                             
                                                                                                                                                                                              
                                                                                               
                                listB:                                                         
                                ([]string) (len=2) {                       
                                 (string) (len=7) "branch1",                                   
                                 (string) (len=7) "branch2"            
                                }                                                              
                Test:           TestRepository_GetBranches
FAIL
Test failed: run test failed, ExitCode=1
FAIL    code.gitea.io/gitea/modules/git 0.464s

Gitea Version

main

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

git version 2.43.0

Operating System

openSUSE Tumbleweed

How are you running Gitea?

N/A

Database

None

@lng2020
Copy link
Member

lng2020 commented Dec 4, 2023

I can test it locally. Have you tried to figure out why you failed? You may inspect the bare repo under modules/git/tests/repos/repo1_bare.

Running tool: /usr/bin/go test -timeout 30s -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git -tags sqlite,sqlite_unlock_notify -v

=== RUN   TestRepository_GetBranches
--- PASS: TestRepository_GetBranches (0.01s)
PASS
ok  	code.gitea.io/gitea/modules/git	0.124s

@lng2020 lng2020 added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Dec 4, 2023
@lunny
Copy link
Member

lunny commented Dec 4, 2023

Maybe you can check your git config under gitea's home directory.

@AdamMajer
Copy link
Contributor Author

It seems it's gogit related. I assume it's assuming that there is some order to git branch listing. Is there suppose to be one?

> /usr/bin/go test -timeout 30s -tags sqlite,sqlite_unlock_notify -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git
ok      code.gitea.io/gitea/modules/git (cached)


> /usr/bin/go test -timeout 30s -tags sqlite,sqlite_unlock_notify,gogit -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git
--- FAIL: TestRepository_GetBranches (0.00s)
    repo_branch_test.go:24: 
                Error Trace:    /home/adamm/work/alp/gitea/gitea/modules/git/repo_branch_test.go:24
                Error:          elements differ
                            
                                extra elements in list A:
                                ([]interface {}) (len=1) {
                                 (string) (len=6) "master"
                                }
                            
                            
                                extra elements in list B:
                                ([]interface {}) (len=1) {
                                 (string) (len=7) "branch1"
                                }
                            
                            
                                listA:
                                ([]string) (len=2) {
                                 (string) (len=6) "master",
                                 (string) (len=7) "branch2"
                                }
                            
                            
                                listB:
                                ([]string) (len=2) {
                                 (string) (len=7) "branch1",
                                 (string) (len=7) "branch2"
                                }
                Test:           TestRepository_GetBranches
FAIL
Test failed: run test failed, ExitCode=1
FAIL    code.gitea.io/gitea/modules/git 0.066s
FAIL

@lng2020 lng2020 removed the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Dec 4, 2023
@AdamMajer
Copy link
Contributor Author

Maybe you can check your git config under gitea's home directory.

It's just gitea checkout. The failure only happens with gogit. I have v5@v5.9.0 which seems to be what gitea requires anyway.

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true

@lng2020
Copy link
Member

lng2020 commented Dec 4, 2023

Yes. It's about the file sequence in gogit. PR to make this test more robust is welcome.

@AdamMajer
Copy link
Contributor Author

Looking at the nogogit implementation,

// GetBranchNames returns branches from the repository, skipping "skip" initial branches and
// returning at most "limit" branches, or all branches if "limit" is 0.
func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) {
	return callShowRef(repo.Ctx, repo.Path, BranchPrefix, TrustedCmdArgs{BranchPrefix, "--sort=-committerdate"}, skip, limit)
}

which means the problem is not gogit itself, it's more the expectation of sort order. This also hints at the solution.

AdamMajer added a commit to AdamMajer/gitea that referenced this issue Dec 4, 2023
nogogit GetBranchNames() lists branches sorted in reverse commit date
order. On the other hand the gogit implementation doesn't apply any
ordering resulting in unpredictable behaviour. In my case, the unit
tests requiring particular order fail

    repo_branch_test.go:24:
                Error Trace:
               ./gitea/modules/git/repo_branch_test.go:24
                Error:          elements differ

                                extra elements in list A:
                                ([]interface {}) (len=1) {
                                 (string) (len=6) "master"
                                }

                                extra elements in list B:
                                ([]interface {}) (len=1) {
                                 (string) (len=7) "branch1"
                                }

                                listA:
                                ([]string) (len=2) {
                                 (string) (len=6) "master",
                                 (string) (len=7) "branch2"
                                }

                                listB:
                                ([]string) (len=2) {
                                 (string) (len=7) "branch1",
                                 (string) (len=7) "branch2"
                                }
                Test:           TestRepository_GetBranches

To fix this, we sort branches based on their commit date in gogit
implementation.

Fixes: go-gitea#28318
AdamMajer added a commit to AdamMajer/gitea that referenced this issue Dec 4, 2023
nogogit GetBranchNames() lists branches sorted in reverse commit date
order. On the other hand the gogit implementation doesn't apply any
ordering resulting in unpredictable behaviour. In my case, the unit
tests requiring particular order fail

    repo_branch_test.go:24:
                Error Trace:
               ./gitea/modules/git/repo_branch_test.go:24
                Error:          elements differ

                                extra elements in list A:
                                ([]interface {}) (len=1) {
                                 (string) (len=6) "master"
                                }

                                extra elements in list B:
                                ([]interface {}) (len=1) {
                                 (string) (len=7) "branch1"
                                }

                                listA:
                                ([]string) (len=2) {
                                 (string) (len=6) "master",
                                 (string) (len=7) "branch2"
                                }

                                listB:
                                ([]string) (len=2) {
                                 (string) (len=7) "branch1",
                                 (string) (len=7) "branch2"
                                }
                Test:           TestRepository_GetBranches

To fix this, we sort branches based on their commit date in gogit
implementation.

Fixes: go-gitea#28318
AdamMajer added a commit to AdamMajer/gitea that referenced this issue Dec 4, 2023
nogogit GetBranchNames() lists branches sorted in reverse commit date
order. On the other hand the gogit implementation doesn't apply any
ordering resulting in unpredictable behaviour. In my case, the unit
tests requiring particular order fail

    repo_branch_test.go:24:
                Error Trace:
               ./gitea/modules/git/repo_branch_test.go:24
                Error:          elements differ

                                extra elements in list A:
                                ([]interface {}) (len=1) {
                                 (string) (len=6) "master"
                                }

                                extra elements in list B:
                                ([]interface {}) (len=1) {
                                 (string) (len=7) "branch1"
                                }

                                listA:
                                ([]string) (len=2) {
                                 (string) (len=6) "master",
                                 (string) (len=7) "branch2"
                                }

                                listB:
                                ([]string) (len=2) {
                                 (string) (len=7) "branch1",
                                 (string) (len=7) "branch2"
                                }
                Test:           TestRepository_GetBranches

To fix this, we sort branches based on their commit date in gogit
implementation.

Fixes: go-gitea#28318
techknowlogick pushed a commit that referenced this issue Dec 7, 2023
Backport #28348 by @AdamMajer

nogogit GetBranchNames() lists branches sorted in reverse commit date
order. On the other hand the gogit implementation doesn't apply any
ordering resulting in unpredictable behaviour. In my case, the unit
tests requiring particular order fail

    repo_branch_test.go:24:
                Error Trace:
               ./gitea/modules/git/repo_branch_test.go:24
                Error:          elements differ

                                extra elements in list A:
                                ([]interface {}) (len=1) {
                                 (string) (len=6) "master"
                                }

                                extra elements in list B:
                                ([]interface {}) (len=1) {
                                 (string) (len=7) "branch1"
                                }

                                listA:
                                ([]string) (len=2) {
                                 (string) (len=6) "master",
                                 (string) (len=7) "branch2"
                                }

                                listB:
                                ([]string) (len=2) {
                                 (string) (len=7) "branch1",
                                 (string) (len=7) "branch2"
                                }
                Test:           TestRepository_GetBranches

To fix this, we sort branches based on their commit date in gogit
implementation.

Fixes: #28318

Co-authored-by: Adam Majer <amajer@suse.de>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2024
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this issue Jan 23, 2025
…gitea#28386)

Backport go-gitea#28348 by @AdamMajer

nogogit GetBranchNames() lists branches sorted in reverse commit date
order. On the other hand the gogit implementation doesn't apply any
ordering resulting in unpredictable behaviour. In my case, the unit
tests requiring particular order fail

    repo_branch_test.go:24:
                Error Trace:
               ./gitea/modules/git/repo_branch_test.go:24
                Error:          elements differ

                                extra elements in list A:
                                ([]interface {}) (len=1) {
                                 (string) (len=6) "master"
                                }

                                extra elements in list B:
                                ([]interface {}) (len=1) {
                                 (string) (len=7) "branch1"
                                }

                                listA:
                                ([]string) (len=2) {
                                 (string) (len=6) "master",
                                 (string) (len=7) "branch2"
                                }

                                listB:
                                ([]string) (len=2) {
                                 (string) (len=7) "branch1",
                                 (string) (len=7) "branch2"
                                }
                Test:           TestRepository_GetBranches

To fix this, we sort branches based on their commit date in gogit
implementation.

Fixes: go-gitea#28318

Co-authored-by: Adam Majer <amajer@suse.de>
(cherry picked from commit 272ae03)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants