Skip to content

Commit

Permalink
[chore] - reduce test time (#2321)
Browse files Browse the repository at this point in the history
* reduce test time

* remove commented out code
  • Loading branch information
ahrav authored Jan 22, 2024
1 parent e803e68 commit 383f8a1
Showing 1 changed file with 18 additions and 42 deletions.
60 changes: 18 additions & 42 deletions pkg/gitparse/gitparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,16 +741,6 @@ func TestIndividualCommitParsing(t *testing.T) {
}
j++
}
//for _, pass := range test.passes {
// if !test.function(false, pass.latestState, pass.line) {
// t.Errorf("%s: Parser did not recognize correct line. (%s)", name, string(pass.line))
// }
//}
//for _, fail := range test.fails {
// if test.function(false, fail.latestState, fail.line) {
// t.Errorf("%s: Parser did not recognize incorrect line. (%s)", name, string(fail.line))
// }
//}
}
}

Expand Down Expand Up @@ -802,24 +792,6 @@ func TestStagedDiffParsing(t *testing.T) {
Content: *bytes.NewBuffer([]byte("The Nameless is the origin of Heaven and Earth;\nThe named is the mother of all things.\n\nTherefore let there always be non-being,\n so we may see their subtlety,\nAnd let there always be being,\n so we may see their outcome.\nThe two are the same,\nBut after they are produced,\n they have different names.\nThey both may be called deep and profound.\nDeeper and more profound,\nThe door of all subtleties!\n")),
IsBinary: false,
},
//{
// PathB: "",
// LineStart: 0,
// Content: *bytes.NewBuffer([]byte("\n")),
// IsBinary: false,
//},
//{
// PathB: "",
// LineStart: 0,
// Content: *bytes.NewBuffer([]byte("\n")),
// IsBinary: false,
//},
//{
// PathB: "",
// LineStart: 0,
// Content: *bytes.NewBuffer([]byte("\n")),
// IsBinary: false,
//},
},
},
}
Expand Down Expand Up @@ -1112,27 +1084,31 @@ index 0000000..5af88a8

func TestMaxDiffSize(t *testing.T) {
parser := NewParser()
bigBytes := bytes.Buffer{}
bigBytes.WriteString(singleCommitSingleDiff)
builder := strings.Builder{}
builder.WriteString(singleCommitSingleDiff)

// Generate a diff that is larger than the maxDiffSize.
for i := 0; i <= parser.maxDiffSize/1024+10; i++ {
bigBytes.WriteString("+")
for n := 0; n < 1024; n++ {
bigBytes.Write([]byte("0"))
}
bigBytes.WriteString("\n")
builder.WriteString("+" + strings.Repeat("0", 1024) + "\n")
}
bigReader := bytes.NewReader(bigBytes.Bytes())
bigReader := strings.NewReader(builder.String())

commitChan := make(chan Commit, 1) // Buffer to prevent blocking
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) // Timeout to prevent long wait
defer cancel()

commitChan := make(chan Commit)
go func() {
parser.FromReader(context.Background(), bigReader, commitChan, false)
parser.FromReader(ctx, bigReader, commitChan, false)
}()

commit := <-commitChan
if commit.Diffs[0].Content.Len() > parser.maxDiffSize+1024 {
t.Errorf("diff did not match MaxDiffSize. Got: %d, expected (max): %d", commit.Diffs[0].Content.Len(), parser.maxDiffSize+1024)
select {
case commit := <-commitChan:
if commit.Diffs[0].Content.Len() > parser.maxDiffSize+1024 {
t.Errorf("diff did not match MaxDiffSize. Got: %d, expected (max): %d", commit.Diffs[0].Content.Len(), parser.maxDiffSize+1024)
}
case <-ctx.Done():
t.Fatal("Test timed out")
}

}

func TestMaxCommitSize(t *testing.T) {
Expand Down

0 comments on commit 383f8a1

Please sign in to comment.