Skip to content

Commit

Permalink
Fix flakey job test (#10807)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier authored Sep 27, 2023
1 parent 05efa5d commit 6b1d465
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
28 changes: 25 additions & 3 deletions core/cmd/jobs_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cmd_test
import (
"bytes"
"flag"
"fmt"
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/urfave/cli"
Expand Down Expand Up @@ -293,6 +295,26 @@ func TestJob_ToRows(t *testing.T) {
}, job.ToRows())
}

const directRequestSpecTemplate = `
type = "directrequest"
schemaVersion = 1
evmChainID = "0"
name = "example eth request event spec"
contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C"
externalJobID = "%s"
observationSource = """
ds1 [type=http method=GET url="http://example.com" allowunrestrictednetworkaccess="true"];
ds1_merge [type=merge left="{}"]
ds1_parse [type=jsonparse path="USD"];
ds1_multiply [type=multiply times=100];
ds1 -> ds1_parse -> ds1_multiply;
"""
`

func getDirectRequestSpec() string {
return fmt.Sprintf(directRequestSpecTemplate, uuid.New())
}

func TestShell_ListFindJobs(t *testing.T) {
t.Parallel()

Expand All @@ -305,7 +327,7 @@ func TestShell_ListFindJobs(t *testing.T) {
fs := flag.NewFlagSet("", flag.ExitOnError)
cltest.FlagSetApplyFromAction(client.CreateJob, fs, "")

require.NoError(t, fs.Parse([]string{"../testdata/tomlspecs/direct-request-spec.toml"}))
require.NoError(t, fs.Parse([]string{getDirectRequestSpec()}))

err := client.CreateJob(cli.NewContext(nil, fs, nil))
require.NoError(t, err)
Expand All @@ -331,7 +353,7 @@ func TestShell_ShowJob(t *testing.T) {
fs := flag.NewFlagSet("", flag.ExitOnError)
cltest.FlagSetApplyFromAction(client.CreateJob, fs, "")

require.NoError(t, fs.Parse([]string{"../testdata/tomlspecs/direct-request-spec.toml"}))
require.NoError(t, fs.Parse([]string{getDirectRequestSpec()}))

err := client.CreateJob(cli.NewContext(nil, fs, nil))
require.NoError(t, err)
Expand Down Expand Up @@ -400,7 +422,7 @@ func TestShell_DeleteJob(t *testing.T) {
fs := flag.NewFlagSet("", flag.ExitOnError)
cltest.FlagSetApplyFromAction(client.CreateJob, fs, "")

require.NoError(t, fs.Parse([]string{"../testdata/tomlspecs/direct-request-spec.toml"}))
require.NoError(t, fs.Parse([]string{getDirectRequestSpec()}))

err := client.CreateJob(cli.NewContext(nil, fs, nil))
require.NoError(t, err)
Expand Down
21 changes: 17 additions & 4 deletions core/services/job/job_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/lib/pq"
"github.com/pelletier/go-toml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v4"
Expand Down Expand Up @@ -217,9 +216,23 @@ func TestORM(t *testing.T) {
})

t.Run("creates a job with a direct request spec", func(t *testing.T) {
tree, err := toml.LoadFile("../../testdata/tomlspecs/direct-request-spec.toml")
require.NoError(t, err)
jb, err := directrequest.ValidatedDirectRequestSpec(tree.String())
drSpec := fmt.Sprintf(`
type = "directrequest"
schemaVersion = 1
evmChainID = "0"
name = "example eth request event spec"
contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C"
externalJobID = "%s"
observationSource = """
ds1 [type=http method=GET url="http://example.com" allowunrestrictednetworkaccess="true"];
ds1_merge [type=merge left="{}"]
ds1_parse [type=jsonparse path="USD"];
ds1_multiply [type=multiply times=100];
ds1 -> ds1_parse -> ds1_multiply;
"""
`, uuid.New())

jb, err := directrequest.ValidatedDirectRequestSpec(drSpec)
require.NoError(t, err)
err = orm.CreateJob(&jb)
require.NoError(t, err)
Expand Down
13 changes: 0 additions & 13 deletions core/testdata/tomlspecs/direct-request-spec.toml

This file was deleted.

18 changes: 17 additions & 1 deletion core/web/jobs_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,23 @@ func setupJobSpecsControllerTestsWithJobs(t *testing.T) (*cltest.TestApplication
err = app.AddJobV2(testutils.Context(t), &jb)
require.NoError(t, err)

erejb, err := directrequest.ValidatedDirectRequestSpec(string(cltest.MustReadFile(t, "../testdata/tomlspecs/direct-request-spec.toml")))
drSpec := fmt.Sprintf(`
type = "directrequest"
schemaVersion = 1
evmChainID = "0"
name = "example eth request event spec"
contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C"
externalJobID = "%s"
observationSource = """
ds1 [type=http method=GET url="http://example.com" allowunrestrictednetworkaccess="true"];
ds1_merge [type=merge left="{}"]
ds1_parse [type=jsonparse path="USD"];
ds1_multiply [type=multiply times=100];
ds1 -> ds1_parse -> ds1_multiply;
"""
`, uuid.New())

erejb, err := directrequest.ValidatedDirectRequestSpec(drSpec)
require.NoError(t, err)
err = app.AddJobV2(testutils.Context(t), &erejb)
require.NoError(t, err)
Expand Down

0 comments on commit 6b1d465

Please sign in to comment.