diff --git a/internal/jstest/jstest.go b/internal/jstest/jstest.go index 4e3e13f7d..945cac52d 100644 --- a/internal/jstest/jstest.go +++ b/internal/jstest/jstest.go @@ -16,8 +16,10 @@ package jstest import ( + "bytes" "context" "errors" + "fmt" "log" "os/exec" "path/filepath" @@ -83,8 +85,7 @@ func Run(ctx context.Context, dir string, args []string) (*internal.TestResults, out []byte } - // tokens is a counting semaphore used to enforce a limit of - // 20 concurrent runCommand invocations. + // tokens is a counting semaphore used to enforce a limit of 20 concurrent calls to runShellWithScript. tokens := make(chan struct{}, 20) ch := make(chan *item, len(files)) @@ -107,7 +108,7 @@ func Run(ctx context.Context, dir string, args []string) (*internal.TestResults, panic(err) } - it.out, it.err = runCommand(dir, "mongo", rel) + it.out, it.err = runShellWithScript(dir, rel) ch <- it <-tokens // release the token @@ -141,16 +142,20 @@ func Run(ctx context.Context, dir string, args []string) (*internal.TestResults, return res, nil } -// runCommand runs command with args inside the mongo container and returns the -// combined output. -func runCommand(dir, command string, args ...string) ([]byte, error) { +// runShellWithScript runs the mongo shell inside a container with script and returns the combined output. +func runShellWithScript(dir, script string) ([]byte, error) { bin, err := exec.LookPath("docker") if err != nil { return nil, err } - args = append([]string{"--verbose", "--norc", "mongodb://host.docker.internal:27017/"}, args...) - dockerArgs := append([]string{"compose", "run", "-T", "--rm", command}, args...) + dockerArgs := []string{"compose", "run", "-T", "--rm", "mongo"} + shellArgs := []string{ + "--verbose", "--norc", "mongodb://host.docker.internal:27017/", + "--eval", evalBuilder(script), script, + } + dockerArgs = append(dockerArgs, shellArgs...) + cmd := exec.Command(bin, dockerArgs...) cmd.Dir = dir @@ -158,3 +163,13 @@ func runCommand(dir, command string, args ...string) ([]byte, error) { return cmd.CombinedOutput() } + +// evalBuilder creates the TestData object and sets the testName property for the shell. +func evalBuilder(script string) string { + var eb bytes.Buffer + fmt.Fprintf(&eb, "TestData = new Object(); ") + scriptName := filepath.Base(script) + fmt.Fprintf(&eb, "TestData.testName = %q;", strings.TrimSuffix(scriptName, filepath.Ext(scriptName))) + + return eb.String() +} diff --git a/tests/dbaas_core.yml b/tests/dbaas_core.yml index ddf847060..e760b9e59 100644 --- a/tests/dbaas_core.yml +++ b/tests/dbaas_core.yml @@ -224,8 +224,9 @@ args: results: ferretdb: stats: - expected_fail: 553 - expected_pass: 254 + expected_fail: 0 + unexpected_fail: 711 + expected_pass: 256 ignore: - mongo/jstests/core/query/explode_for_sort_fetch.js pass: @@ -243,5 +244,5 @@ results: mongodb: stats: expected_fail: 0 - unexpected_fail: 71 - expected_pass: 897 + unexpected_fail: 53 + expected_pass: 915 diff --git a/tests/mongo.yml b/tests/mongo.yml index f9c209179..a7aea49b8 100644 --- a/tests/mongo.yml +++ b/tests/mongo.yml @@ -28,8 +28,8 @@ args: results: ferretdb: stats: - expected_fail: 40 - expected_pass: 37 + expected_fail: 39 + expected_pass: 38 fail: # https://docs.ferretdb.io/diff/ @@ -114,18 +114,16 @@ results: # document keys must not contain $ or . signs; - mongo/jstests/core/write/update/updateh.js - # https://github.com/FerretDB/dance/issues/294 - - mongo/jstests/readonly/get_more.js + # same issue, see below. - mongo/jstests/auth/getMore.js - mongo/jstests/auth/list_sessions.js mongodb: stats: - expected_fail: 3 - expected_pass: 74 - + expected_fail: 2 + expected_pass: 75 fail: - # https://github.com/FerretDB/dance/issues/294 + # both tests invoke the MongoRunner and also fail on resmoke.py with exit code 253. + # they both seem to use a key file with incorrect permissions. - mongo/jstests/auth/getMore.js - - mongo/jstests/readonly/get_more.js - mongo/jstests/auth/list_sessions.js