Skip to content

Commit

Permalink
fix, Define a timeout for the "symflower unit-tests" command, so ensu…
Browse files Browse the repository at this point in the history
…re the execution does not take too much time

Closes #167
  • Loading branch information
ruiAzevedo19 committed Jul 15, 2024
1 parent 279901e commit 09876e5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion model/symflower/symflower.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
pkgerrors "github.com/pkg/errors"

"github.com/symflower/eval-dev-quality/evaluate/metrics"
"github.com/symflower/eval-dev-quality/language"
"github.com/symflower/eval-dev-quality/model"
"github.com/symflower/eval-dev-quality/provider"
"github.com/symflower/eval-dev-quality/tools"
Expand All @@ -35,9 +36,12 @@ var _ model.CapabilityWriteTests = (*Model)(nil)

// generateTestsForFile generates test files for the given implementation file in a repository.
func (m *Model) WriteTests(ctx model.Context) (assessment metrics.Assessments, err error) {
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), language.DefaultExecutionTimeout)
defer cancel()

start := time.Now()

output, err := util.CommandWithResult(context.Background(), ctx.Logger, &util.Command{
output, err := util.CommandWithResult(ctxWithTimeout, ctx.Logger, &util.Command{
Command: []string{
tools.SymflowerPath, "unit-tests",
"--code-disable-fetch-dependencies",
Expand Down
38 changes: 38 additions & 0 deletions model/symflower/symflower_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package symflower

import (
"context"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -17,6 +19,7 @@ import (
"github.com/symflower/eval-dev-quality/model"
"github.com/symflower/eval-dev-quality/tools"
toolstesting "github.com/symflower/eval-dev-quality/tools/testing"
"github.com/symflower/eval-dev-quality/util"
)

func TestModelGenerateTestsForFile(t *testing.T) {
Expand Down Expand Up @@ -257,3 +260,38 @@ func TestCountCharactersOfGeneratedFiles(t *testing.T) {
ExpectedCount: 169,
})
}

func TestSymflowerUnitTestsWithTimeout(t *testing.T) {
logOutput, logger := log.Buffer()
defer func() {
if t.Failed() {
t.Log(logOutput.String())
}
}()

temporaryDirectory := t.TempDir()
repositoryPath := filepath.Join(temporaryDirectory, "testdata", "java", "light")
require.NoError(t, osutil.CopyTree(filepath.Join("..", "..", "testdata", "java", "light"), repositoryPath))

ctxWithTimeout, cancel := context.WithTimeout(context.Background(), time.Duration(1*time.Millisecond))
defer cancel()

start := time.Now()
_, err := util.CommandWithResult(ctxWithTimeout, logger, &util.Command{
Command: []string{
tools.SymflowerPath, "unit-tests",
"--code-disable-fetch-dependencies",
"--workspace", repositoryPath,
},

Directory: repositoryPath,
})
duration := time.Since(start)

if osutil.IsWindows() {
assert.ErrorContains(t, err, context.DeadlineExceeded.Error())
} else {
assert.ErrorContains(t, err, "signal: killed")
}
assert.Less(t, duration.Seconds(), 1.0)
}

0 comments on commit 09876e5

Please sign in to comment.