Skip to content

Commit

Permalink
Set TestData object to allow more tests to run (#474)
Browse files Browse the repository at this point in the history
Closes #294.
  • Loading branch information
b1ron authored Jun 9, 2023
1 parent ef3d77d commit 3fb1a6a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
31 changes: 23 additions & 8 deletions internal/jstest/jstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package jstest

import (
"bytes"
"context"
"errors"
"fmt"
"log"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -141,20 +142,34 @@ 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

log.Printf("Running %s", strings.Join(cmd.Args, " "))

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()
}
9 changes: 5 additions & 4 deletions tests/dbaas_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -243,5 +244,5 @@ results:
mongodb:
stats:
expected_fail: 0
unexpected_fail: 71
expected_pass: 897
unexpected_fail: 53
expected_pass: 915
16 changes: 7 additions & 9 deletions tests/mongo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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

0 comments on commit 3fb1a6a

Please sign in to comment.