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

Set TestData object to allow more tests to run #474

Merged
merged 25 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 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,56 @@ 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, nil), script,
}
dockerArgs = append(dockerArgs, shellArgs...)

cmd := exec.Command(bin, dockerArgs...)
cmd.Dir = dir

log.Printf("Running %s", strings.Join(cmd.Args, " "))
log.Printf("Running %s", script)
AlekSi marked this conversation as resolved.
Show resolved Hide resolved

return cmd.CombinedOutput()
}

// evalBuilder creates the TestData object and sets the testName property for the shell.
// It optionally sets additional properties on the TestData object.
func evalBuilder(script string, obj map[string]string) string {
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
var eb bytes.Buffer
eb.WriteString("TestData = new Object();")
eb.WriteByte(' ')
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
scriptName := filepath.Base(script)
fmt.Fprintf(&eb, "TestData.testName = %q;", strings.TrimSuffix(scriptName, filepath.Ext(scriptName)))

if obj == nil {
return eb.String()
}

eb.WriteByte(' ')

// avoids extraneous space
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
i := len(obj) - 1

for key, value := range obj {
fmt.Fprintf(&eb, "TestData.%s = %s;", key, value)
AlekSi marked this conversation as resolved.
Show resolved Hide resolved

if i == 0 {
break
}
i--

eb.WriteByte(' ')
}

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