Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ go-postgres-unit-tests: build-prep test-prep
@# The -p 1 passed to go test is required to ensure that tests of different packages are not run in parallel, so as to avoid conflicts when interacting with the DB.
set -o pipefail ; \
CGO_ENABLED=1 GODEBUG=cgocheck=2 MUTEX_WATCHDOG_TIMEOUT_SECS=30 ROX_POSTGRES_DATASTORE=true GOTAGS=$(GOTAGS),test,sql_integration scripts/go-test.sh -p 1 -race -cover -coverprofile test-output/coverage.out -v \
$(shell git ls-files -- '*postgres/*_test.go' '*postgres_test.go' '*datastore_sac_test.go' '*clone_test.go' | sed -e 's@^@./@g' | xargs -n 1 dirname | sort | uniq | xargs go list| grep -v '^github.com/stackrox/rox/tests$$' | grep -Ev $(UNIT_TEST_IGNORE)) \
$(shell git ls-files -- '*postgres/*_test.go' '*postgres_test.go' '*datastore_sac_test.go' '*clone_test.go' 'migrator/migrations/n_*/migration_test.go' | sed -e 's@^@./@g' | xargs -n 1 dirname | sort | uniq | xargs go list| grep -v '^github.com/stackrox/rox/tests$$' | grep -Ev $(UNIT_TEST_IGNORE)) \
| tee $(GO_TEST_OUTPUT_PATH)

.PHONY: shell-unit-tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *postgresMigrationSuite) TearDownTest() {
}

var (
deploymentID = "depA"
deploymentID = "536c3ce3-aa06-49fb-b6de-a056a03c545c"
componentName = "bash"
os = []string{"rhel:8", "debian:10"}
versions = []string{"v1", "v2"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func (s *postgresMigrationSuite) populateStore(clusterStore store.ClusterStore,
return flowStore, flows
}

func roundTimestampToMicroseconds(timestamp *types.Timestamp) {
if timestamp == nil {
return
}
timestampNanos := timestamp.GetNanos()
timestampNanos /= 1000
timestampNanos *= 1000
timestamp.Nanos = timestampNanos
}

func (s *postgresMigrationSuite) verify(flowStore store.FlowStore, flows []*storage.NetworkFlow) {
fetched, _, err := flowStore.GetAllFlows(s.ctx, &types.Timestamp{})
s.NoError(err)
Expand All @@ -86,6 +96,9 @@ func (s *postgresMigrationSuite) verify(flowStore store.FlowStore, flows []*stor
return flows[i].LastSeenTimestamp.Compare(flows[j].LastSeenTimestamp) < 0
})
for i, flow := range flows {
// Postgres Datetime columns only have microsecond granularity for timestamps.
// Adapt the input data to take this into account.
roundTimestampToMicroseconds(flow.GetLastSeenTimestamp())
s.Equal(flow, fetched[i])
}
}
Expand All @@ -95,13 +108,13 @@ func (s *postgresMigrationSuite) TestNetworkFlowMigration() {
legacyStore := legacy.NewClusterStore(s.legacyDB)

// Prepare data and write to legacy DB
_, cluster1Flows := s.populateStore(legacyStore, "cluster1")
_, cluster2Flows := s.populateStore(legacyStore, "cluster2")
_, cluster1Flows := s.populateStore(legacyStore, "b3bf0acc-f870-4456-8730-f8b39cf59009")
_, cluster2Flows := s.populateStore(legacyStore, "a78f0c04-fb07-41ce-908b-1e07e1fb5674")

// Move
s.NoError(move(s.postgresDB.GetGormDB(), s.postgresDB.Pool, legacyStore))

// Verify
s.verify(newStore.GetFlowStore("cluster1"), cluster1Flows)
s.verify(newStore.GetFlowStore("cluster2"), cluster2Flows)
s.verify(newStore.GetFlowStore("b3bf0acc-f870-4456-8730-f8b39cf59009"), cluster1Flows)
s.verify(newStore.GetFlowStore("a78f0c04-fb07-41ce-908b-1e07e1fb5674"), cluster2Flows)
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *postgresMigrationSuite) TestMigration() {
// Prepare data and write to legacy DB
nodes := []*storage.Node{
{
Id: "id1",
Id: "b7766f6d-5e03-474c-834a-34250bf323a6",
Name: "node1",
Scan: &storage.NodeScan{
Components: []*storage.EmbeddedNodeScanComponent{
Expand Down Expand Up @@ -96,7 +96,7 @@ func (s *postgresMigrationSuite) TestMigration() {
},
},
{
Id: "id2",
Id: "caa1f009-c3ba-4ef6-a371-8932d8212505",
Name: "node2",
Scan: &storage.NodeScan{
Components: []*storage.EmbeddedNodeScanComponent{
Expand Down