chore(multiregion): fix test docker config and test
This commit is contained in:
@@ -598,10 +598,18 @@ jobs:
|
||||
POSTGRES_PASSWORD: speckle
|
||||
POSTGRES_USER: speckle
|
||||
command: -c 'max_connections=1000' -c 'port=5433' -c 'wal_level=logical'
|
||||
- image: 'speckle/speckle-postgres'
|
||||
environment:
|
||||
POSTGRES_DB: speckle2_test
|
||||
POSTGRES_PASSWORD: speckle
|
||||
POSTGRES_USER: speckle
|
||||
command: -c 'max_connections=1000' -c 'port=5434' -c 'wal_level=logical'
|
||||
- image: 'minio/minio'
|
||||
command: server /data --console-address ":9001" --address "0.0.0.0:9000"
|
||||
- image: 'minio/minio'
|
||||
command: server /data --console-address ":9021" --address "0.0.0.0:9020"
|
||||
- image: 'minio/minio'
|
||||
command: server /data --console-address ":9041" --address "0.0.0.0:9040"
|
||||
environment:
|
||||
# Same as test-server:
|
||||
NODE_ENV: test
|
||||
|
||||
@@ -207,10 +207,10 @@ export const copyProjectVersionsFactory =
|
||||
|
||||
for await (const versions of executeBatchedSelect(selectVersions)) {
|
||||
for (const version of versions) {
|
||||
const { commitId, ...commit } = version
|
||||
const { commitId, streamId, ...commit } = version
|
||||
|
||||
// Store copied version id
|
||||
copiedVersionIds[projectId].push(commitId)
|
||||
copiedVersionIds[streamId].push(commitId)
|
||||
|
||||
// Copy `commits` row to target db
|
||||
await tables.versions(deps.targetDb).insert(commit).onConflict().ignore()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { db } from '@/db/knex'
|
||||
import { AllScopes } from '@/modules/core/helpers/mainConstants'
|
||||
import { createRandomEmail } from '@/modules/core/helpers/testHelpers'
|
||||
import { StreamRecord } from '@/modules/core/helpers/types'
|
||||
import { BranchRecord, CommitRecord, StreamRecord } from '@/modules/core/helpers/types'
|
||||
import { grantStreamPermissionsFactory } from '@/modules/core/repositories/streams'
|
||||
import { getDb } from '@/modules/multiregion/utils/dbSelector'
|
||||
import {
|
||||
@@ -28,6 +28,12 @@ import {
|
||||
TestApolloServer
|
||||
} from '@/test/graphqlHelper'
|
||||
import { beforeEachContext } from '@/test/hooks'
|
||||
import { BasicTestBranch, createTestBranch } from '@/test/speckle-helpers/branchHelper'
|
||||
import {
|
||||
BasicTestCommit,
|
||||
createTestCommit,
|
||||
createTestObject
|
||||
} from '@/test/speckle-helpers/commitHelper'
|
||||
import {
|
||||
isMultiRegionTestMode,
|
||||
waitForRegionUser
|
||||
@@ -37,6 +43,7 @@ import { Roles } from '@speckle/shared'
|
||||
import { expect } from 'chai'
|
||||
import cryptoRandomString from 'crypto-random-string'
|
||||
import { Knex } from 'knex'
|
||||
import { SetOptional } from 'type-fest'
|
||||
|
||||
const grantStreamPermissions = grantStreamPermissionsFactory({ db })
|
||||
|
||||
@@ -294,10 +301,9 @@ isMultiRegionTestMode()
|
||||
email: createRandomEmail()
|
||||
}
|
||||
|
||||
const testWorkspace: BasicTestWorkspace = {
|
||||
const testWorkspace: SetOptional<BasicTestWorkspace, 'slug'> = {
|
||||
id: '',
|
||||
ownerId: '',
|
||||
slug: '',
|
||||
name: 'Unlimited Workspace'
|
||||
}
|
||||
|
||||
@@ -308,12 +314,34 @@ isMultiRegionTestMode()
|
||||
isPublic: true
|
||||
}
|
||||
|
||||
const testModel: BasicTestBranch = {
|
||||
id: '',
|
||||
name: cryptoRandomString({ length: 8 }),
|
||||
streamId: '',
|
||||
authorId: ''
|
||||
}
|
||||
|
||||
const testVersion: BasicTestCommit = {
|
||||
id: '',
|
||||
objectId: '',
|
||||
streamId: '',
|
||||
authorId: ''
|
||||
}
|
||||
|
||||
let apollo: TestApolloServer
|
||||
let regionDb: Knex
|
||||
let targetRegionDb: Knex
|
||||
|
||||
before(async () => {
|
||||
await createTestUser(adminUser)
|
||||
await waitForRegionUser(adminUser)
|
||||
|
||||
apollo = await testApolloServer({ authUserId: adminUser.id })
|
||||
targetRegionDb = await getDb({ regionKey: regionKey2 })
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
delete testWorkspace.slug
|
||||
|
||||
await createTestWorkspace(testWorkspace, adminUser, {
|
||||
regionKey: regionKey1,
|
||||
addPlan: {
|
||||
@@ -324,12 +352,20 @@ isMultiRegionTestMode()
|
||||
|
||||
testProject.workspaceId = testWorkspace.id
|
||||
|
||||
apollo = await testApolloServer({ authUserId: adminUser.id })
|
||||
regionDb = await getDb({ regionKey: regionKey2 })
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createTestStream(testProject, adminUser)
|
||||
await createTestBranch({
|
||||
stream: testProject,
|
||||
branch: testModel,
|
||||
owner: adminUser
|
||||
})
|
||||
|
||||
testVersion.branchName = testModel.name
|
||||
testVersion.objectId = await createTestObject({ projectId: testProject.id })
|
||||
|
||||
await createTestCommit(testVersion, {
|
||||
owner: adminUser,
|
||||
stream: testProject
|
||||
})
|
||||
})
|
||||
|
||||
it('moves project record to target regional db', async () => {
|
||||
@@ -340,7 +376,7 @@ isMultiRegionTestMode()
|
||||
|
||||
expect(res).to.not.haveGraphQLErrors()
|
||||
|
||||
const project = await regionDb
|
||||
const project = await targetRegionDb
|
||||
.table<StreamRecord>('streams')
|
||||
.select('*')
|
||||
.where({ id: testProject.id })
|
||||
@@ -348,5 +384,39 @@ isMultiRegionTestMode()
|
||||
|
||||
expect(project).to.not.be.undefined
|
||||
})
|
||||
|
||||
it('moves project models to target regional db', async () => {
|
||||
const res = await apollo.execute(UpdateProjectRegionDocument, {
|
||||
projectId: testProject.id,
|
||||
regionKey: regionKey2
|
||||
})
|
||||
|
||||
expect(res).to.not.haveGraphQLErrors()
|
||||
|
||||
const branch = await targetRegionDb
|
||||
.table<BranchRecord>('branches')
|
||||
.select('*')
|
||||
.where({ id: testModel.id })
|
||||
.first()
|
||||
|
||||
expect(branch).to.not.be.undefined
|
||||
})
|
||||
|
||||
it('moves project model versions to target regional db', async () => {
|
||||
const res = await apollo.execute(UpdateProjectRegionDocument, {
|
||||
projectId: testProject.id,
|
||||
regionKey: regionKey2
|
||||
})
|
||||
|
||||
expect(res).to.not.haveGraphQLErrors()
|
||||
|
||||
const version = await targetRegionDb
|
||||
.table<CommitRecord>('commits')
|
||||
.select('*')
|
||||
.where({ id: testVersion.id })
|
||||
.first()
|
||||
|
||||
expect(version).to.not.be.undefined
|
||||
})
|
||||
})
|
||||
: void 0
|
||||
|
||||
Reference in New Issue
Block a user