Skip to content

Commit

Permalink
fix: failing test. Also added test for check statuses reconcilation.
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
adityathebe committed Jul 26, 2023
1 parent 4e085fd commit 361e271
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 21 additions & 5 deletions upstream/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
var _ = ginkgo.Describe("Push Mode reconcilation", ginkgo.Ordered, func() {
const randomConfigItemCount = 2000 // keep it below 5k (must be set w.r.t the page size)

ginkgo.It("should populate the agent database with the 5 tables that are reconciled", func() {
ginkgo.It("should populate the agent database with the 6 tables that are reconciled", func() {
err := dummy.PopulateDBWithDummyModels(agentDB)
Expect(err).To(BeNil())

Expand All @@ -40,24 +40,31 @@ var _ = ginkgo.Describe("Push Mode reconcilation", ginkgo.Ordered, func() {
compareItemsCount[models.ConfigScraper](agentDB, 1)
compareItemsCount[models.Canary](agentDB, len(dummy.AllDummyCanaries))
compareItemsCount[models.Check](agentDB, len(dummy.AllDummyChecks))
compareItemsCount[models.CheckStatus](agentDB, len(dummy.AllDummyCheckStatuses))

// Upstream must have no records
compareItemsCount[models.Component](upstreamDB, 0)
compareItemsCount[models.ConfigItem](upstreamDB, 0)
compareItemsCount[models.ConfigScraper](upstreamDB, 0)
compareItemsCount[models.Canary](upstreamDB, 0)
compareItemsCount[models.Check](upstreamDB, 0)
compareItemsCount[models.CheckStatus](upstreamDB, 0)
})

ginkgo.It("should return different hash for agent and upstream", func() {
ctx := api.NewContext(agentDB, nil)
upstreamCtx := api.NewContext(upstreamDB, nil)

for _, table := range api.TablesToReconcile {
agentStatus, err := upstream.GetPrimaryKeysHash(ctx, upstream.PaginateRequest{From: "", Table: table, Size: 500}, uuid.Nil)
paginateRequest := upstream.PaginateRequest{From: "", Table: table, Size: 500}
if table == "check_statuses" {
paginateRequest.From = ","
}

agentStatus, err := upstream.GetPrimaryKeysHash(ctx, paginateRequest, uuid.Nil)
Expect(err).To(BeNil())

upstreamStatus, err := upstream.GetPrimaryKeysHash(upstreamCtx, upstream.PaginateRequest{From: "", Table: table, Size: 500}, uuid.Nil)
upstreamStatus, err := upstream.GetPrimaryKeysHash(upstreamCtx, paginateRequest, uuid.Nil)
Expect(err).To(BeNil())

Expect(agentStatus).ToNot(Equal(upstreamStatus), fmt.Sprintf("table [%s] hash to not match", table))
Expand All @@ -79,10 +86,15 @@ var _ = ginkgo.Describe("Push Mode reconcilation", ginkgo.Ordered, func() {
upstreamCtx := api.NewContext(upstreamDB, nil)

for _, table := range api.TablesToReconcile {
agentStatus, err := upstream.GetPrimaryKeysHash(ctx, upstream.PaginateRequest{From: "", Table: table, Size: 500}, uuid.Nil)
paginateRequest := upstream.PaginateRequest{From: "", Table: table, Size: 500}
if table == "check_statuses" {
paginateRequest.From = ","
}

agentStatus, err := upstream.GetPrimaryKeysHash(ctx, paginateRequest, uuid.Nil)
Expect(err).To(BeNil())

upstreamStatus, err := upstream.GetPrimaryKeysHash(upstreamCtx, upstream.PaginateRequest{From: "", Table: table, Size: 500}, uuid.Nil)
upstreamStatus, err := upstream.GetPrimaryKeysHash(upstreamCtx, paginateRequest, agentID)
Expect(err).To(BeNil())

Expect(agentStatus).To(Equal(upstreamStatus), fmt.Sprintf("table [%s] hash to match", table))
Expand All @@ -105,6 +117,10 @@ var _ = ginkgo.Describe("Push Mode reconcilation", ginkgo.Ordered, func() {
compareEntities(upstreamDB, agentDB, &[]models.Check{})
})

ginkgo.It("should have transferred all the check statuses", func() {
compareEntities(upstreamDB, agentDB, &[]models.CheckStatus{})
})

ginkgo.It("should have transferred all the canaries", func() {
compareEntities(upstreamDB, agentDB, &[]models.Canary{})
})
Expand Down
4 changes: 3 additions & 1 deletion upstream/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/flanksource/duty/upstream"
"github.com/flanksource/incident-commander/api"
"github.com/flanksource/incident-commander/testutils"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/labstack/echo/v4"
ginkgo "github.com/onsi/ginkgo/v2"
Expand All @@ -32,6 +33,7 @@ var (
upstreamEchoServerport = 11006
upstreamEchoServer *echo.Echo

agentID = uuid.New()
agentName = "test-agent"
agentDB *gorm.DB
agentDBPGPool *pgxpool.Pool
Expand All @@ -56,7 +58,7 @@ var _ = ginkgo.BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())

upstreamDB, upstreamPool = testutils.SetupDBConnection(upstreamDBName, pgServerPort)
Expect(upstreamDB.Create(&models.Agent{Name: agentName}).Error).To(BeNil())
Expect(upstreamDB.Create(&models.Agent{ID: agentID, Name: agentName}).Error).To(BeNil())

setupUpstreamHTTPServer()
})
Expand Down

0 comments on commit 361e271

Please sign in to comment.