Skip to content

Commit

Permalink
Enables dynamic placement of logs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra authored Nov 30, 2021
1 parent 17eb653 commit d830525
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
8 changes: 4 additions & 4 deletions actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/onsi/ginkgo/v2"
"github.com/smartcontractkit/helmenv/environment"
"github.com/smartcontractkit/integrations-framework/utils"

"github.com/smartcontractkit/integrations-framework/contracts"

Expand Down Expand Up @@ -151,12 +150,13 @@ func GetMockserverInitializerDataForOTPE(
return initializers, nil
}

// TeardownSuite tears down networks/clients and environment
func TeardownSuite(env *environment.Environment, nets *client.Networks) error {
// TeardownSuite tears down networks/clients and environment and creates a logs folder for failed tests in the
// specified path
func TeardownSuite(env *environment.Environment, nets *client.Networks, logsFolderPath string) error {
if ginkgo.CurrentSpecReport().Failed() {
testFilename := strings.Split(ginkgo.CurrentSpecReport().FileName(), ".")[0]
_, testName := filepath.Split(testFilename)
logsPath := filepath.Join(utils.ProjectRoot, DefaultArtifactsDir, fmt.Sprintf("%s-%d", testName, time.Now().Unix()))
logsPath := filepath.Join(logsFolderPath, DefaultArtifactsDir, fmt.Sprintf("%s-%d", testName, time.Now().Unix()))
if err := env.Artifacts.DumpTestResult(logsPath, "chainlink"); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion suite/smoke/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/smartcontractkit/helmenv/tools"
"github.com/smartcontractkit/integrations-framework/actions"
"github.com/smartcontractkit/integrations-framework/client"
"github.com/smartcontractkit/integrations-framework/utils"
)

var _ = Describe("Cronjob suite @cron", func() {
Expand Down Expand Up @@ -76,7 +77,7 @@ var _ = Describe("Cronjob suite @cron", func() {

AfterEach(func() {
By("Tearing down the environment", func() {
err = actions.TeardownSuite(e, nil)
err = actions.TeardownSuite(e, nil, utils.ProjectRoot)
Expect(err).ShouldNot(HaveOccurred())
})
})
Expand Down
3 changes: 2 additions & 1 deletion suite/smoke/flux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/smartcontractkit/helmenv/environment"
"github.com/smartcontractkit/helmenv/tools"
"github.com/smartcontractkit/integrations-framework/actions"
"github.com/smartcontractkit/integrations-framework/utils"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -172,7 +173,7 @@ var _ = Describe("Flux monitor suite @flux", func() {
nets.Default.GasStats().PrintStats()
})
By("Tearing down the environment", func() {
err = actions.TeardownSuite(e, nets)
err = actions.TeardownSuite(e, nets, utils.ProjectRoot)
Expect(err).ShouldNot(HaveOccurred())
})
})
Expand Down
3 changes: 2 additions & 1 deletion suite/smoke/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/smartcontractkit/integrations-framework/actions"
"github.com/smartcontractkit/integrations-framework/client"
"github.com/smartcontractkit/integrations-framework/contracts"
"github.com/smartcontractkit/integrations-framework/utils"
)

var _ = Describe("Keeper suite @keeper", func() {
Expand Down Expand Up @@ -170,7 +171,7 @@ var _ = Describe("Keeper suite @keeper", func() {
nets.Default.GasStats().PrintStats()
})
By("Tearing down the environment", func() {
err = actions.TeardownSuite(e, nets)
err = actions.TeardownSuite(e, nets, utils.ProjectRoot)
Expect(err).ShouldNot(HaveOccurred())
})
})
Expand Down
4 changes: 3 additions & 1 deletion suite/smoke/ocr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package smoke

import (
"context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/smartcontractkit/helmenv/environment"
"github.com/smartcontractkit/helmenv/tools"
"github.com/smartcontractkit/integrations-framework/actions"
"github.com/smartcontractkit/integrations-framework/client"
"github.com/smartcontractkit/integrations-framework/contracts"
"github.com/smartcontractkit/integrations-framework/utils"
)

var _ = Describe("OCR Feed @ocr", func() {
Expand Down Expand Up @@ -79,7 +81,7 @@ var _ = Describe("OCR Feed @ocr", func() {
networks.Default.GasStats().PrintStats()
})
By("Tearing down the environment", func() {
err = actions.TeardownSuite(env, networks)
err = actions.TeardownSuite(env, networks, utils.ProjectRoot)
Expect(err).ShouldNot(HaveOccurred())
})
})
Expand Down
5 changes: 2 additions & 3 deletions suite/smoke/runlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/smartcontractkit/integrations-framework/actions"
"github.com/smartcontractkit/integrations-framework/client"
"github.com/smartcontractkit/integrations-framework/contracts"
"github.com/smartcontractkit/integrations-framework/utils"
)

var _ = Describe("Direct request suite @runlog", func() {
Expand Down Expand Up @@ -125,10 +126,8 @@ var _ = Describe("Direct request suite @runlog", func() {
AfterEach(func() {
By("Tearing down the environment", func() {
nets.Default.GasStats().PrintStats()
err = actions.TeardownSuite(e, nets)
err = actions.TeardownSuite(e, nets, utils.ProjectRoot)
Expect(err).ShouldNot(HaveOccurred())
//err = e.Disconnect()
//Expect(err).ShouldNot(HaveOccurred())
})
})
})
26 changes: 21 additions & 5 deletions suite/smoke/vrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/smartcontractkit/integrations-framework/actions"
"github.com/smartcontractkit/integrations-framework/client"
"github.com/smartcontractkit/integrations-framework/contracts"
"github.com/smartcontractkit/integrations-framework/utils"
)

var _ = Describe("VRF suite @vrf", func() {
Expand All @@ -27,6 +29,7 @@ var _ = Describe("VRF suite @vrf", func() {
lt contracts.LinkToken
cls []client.Chainlink
e *environment.Environment
job *client.Job
)

BeforeEach(func() {
Expand All @@ -52,7 +55,7 @@ var _ = Describe("VRF suite @vrf", func() {
})

By("Funding Chainlink nodes", func() {
txCost, err := nets.Default.EstimateCostForChainlinkOperations(4)
txCost, err := nets.Default.EstimateCostForChainlinkOperations(1)
Expect(err).ShouldNot(HaveOccurred())
err = actions.FundChainlinkNodes(cls, nets.Default, txCost)
Expect(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -87,7 +90,7 @@ var _ = Describe("VRF suite @vrf", func() {
}
ost, err := os.String()
Expect(err).ShouldNot(HaveOccurred())
_, err = n.CreateJob(&client.VRFJobSpec{
job, err = n.CreateJob(&client.VRFJobSpec{
Name: fmt.Sprintf("vrf-%s", jobUUID),
CoordinatorAddress: coordinator.Address(),
PublicKey: pubKeyCompressed,
Expand Down Expand Up @@ -120,12 +123,25 @@ var _ = Describe("VRF suite @vrf", func() {
err = consumer.RequestRandomness(requestHash, big.NewInt(1))
Expect(err).ShouldNot(HaveOccurred())

timeout := time.Minute * 2

Eventually(func(g Gomega) {
jobRuns, err := cls[0].ReadRunsByJob(job.Data.ID)
g.Expect(err).ShouldNot(HaveOccurred())

out, err := consumer.RandomnessOutput(context.Background())
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(out.Uint64()).Should(Not(BeNumerically("==", 0)))
// Checks that the job has actually run
g.Expect(len(jobRuns.Data)).Should(BeNumerically(">=", 1),
fmt.Sprintf("Expected the VRF job to run once or more after %s", timeout))

// TODO: This is an imperfect check, given it's a random number, it CAN be 0, but chances are unlikely.
// So we're just checking that the answer has changed to something other than the default (0)
// There's a better formula to ensure that VRF response is as expected, detailed under Technical Walkthrough.
// https://blog.chain.link/chainlink-vrf-on-chain-verifiable-randomness/
g.Expect(out.Uint64()).Should(Not(BeNumerically("==", 0)), "Expected the VRF job give an answer other than 0")
log.Debug().Uint64("Output", out.Uint64()).Msg("Randomness fulfilled")
}, "2m", "1s").Should(Succeed())
}, timeout, "1s").Should(Succeed())
})
})

Expand All @@ -134,7 +150,7 @@ var _ = Describe("VRF suite @vrf", func() {
nets.Default.GasStats().PrintStats()
})
By("Tearing down the environment", func() {
err = actions.TeardownSuite(e, nets)
err = actions.TeardownSuite(e, nets, utils.ProjectRoot)
Expect(err).ShouldNot(HaveOccurred())
})
})
Expand Down

0 comments on commit d830525

Please sign in to comment.