|
| 1 | +import { ENV, queryXml, store } from '@ownclouders/k6-tdk/lib/utils' |
| 2 | +import { sleep } from 'k6' |
| 3 | +import exec from 'k6/execution' |
| 4 | +import { Counter } from 'k6/metrics' |
| 5 | +import { Options } from 'k6/options' |
| 6 | + |
| 7 | +import { Client, obtainDocumentInformation } from '@/clients/cool' |
| 8 | +import { userPool } from '@/pools' |
| 9 | +import { clientFor } from '@/shortcuts' |
| 10 | +import { getTestRoot } from '@/test' |
| 11 | +import { getPoolItem } from '@/utils' |
| 12 | +import { envValues } from '@/values' |
| 13 | + |
| 14 | +export interface Environment { |
| 15 | + testRoot: string; |
| 16 | +} |
| 17 | + |
| 18 | +// eslint-disable-next-line no-restricted-globals |
| 19 | +const docX = open('../data/sample.docx', 'b') |
| 20 | + |
| 21 | +export const options: Options = { |
| 22 | + vus: 1, |
| 23 | + iterations: 1, |
| 24 | + insecureSkipTLSVerify: true |
| 25 | +} |
| 26 | + |
| 27 | +const settings = { |
| 28 | + ...envValues(), |
| 29 | + get docx() { |
| 30 | + return ENV('DOCX', [settings.seed.resource.root, 'sample.docx'].join('/')) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +const coolClientErrors = new Counter('cool_client_errors') |
| 35 | + |
| 36 | +export const open_change_save_010_setup = async (): Promise<Environment> => { |
| 37 | + const adminClient = clientFor({ userLogin: settings.admin.login, userPassword: settings.admin.password }) |
| 38 | + const rootInfo = await getTestRoot({ |
| 39 | + client: adminClient, |
| 40 | + userLogin: settings.admin.login, |
| 41 | + platform: settings.platform.type, |
| 42 | + resourceName: settings.seed.container.name, |
| 43 | + resourceType: settings.seed.container.type, |
| 44 | + isOwner: false |
| 45 | + }) |
| 46 | + |
| 47 | + const testRoot = [rootInfo.root, rootInfo.path].join('/') |
| 48 | + |
| 49 | + adminClient.resource.uploadResource({ |
| 50 | + root: testRoot, |
| 51 | + resourcePath: settings.docx, |
| 52 | + resourceBytes: docX |
| 53 | + }) |
| 54 | + |
| 55 | + return { |
| 56 | + testRoot |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +export const open_change_save_010 = async ({ testRoot }: Environment): Promise<void> => { |
| 61 | + const user = getPoolItem({ pool: userPool, n: exec.vu.idInTest }) |
| 62 | + const userStore = store(user.userLogin) |
| 63 | + const documentInformation = await userStore.setOrGet('root', async () => { |
| 64 | + const ocisClient = clientFor(user) |
| 65 | + |
| 66 | + const getResourcePropertiesResponse = await ocisClient.resource.getResourceProperties({ |
| 67 | + root: testRoot, |
| 68 | + resourcePath: settings.docx |
| 69 | + }) |
| 70 | + sleep(settings.sleep.after_request) |
| 71 | + |
| 72 | + const [resourceId] = queryXml("$..['oc:fileid']", getResourcePropertiesResponse.body) |
| 73 | + return obtainDocumentInformation({ client: ocisClient, appName: settings.cool.app_name, resourceId }) |
| 74 | + }) |
| 75 | + |
| 76 | + const { app_url } = documentInformation |
| 77 | + |
| 78 | + const coolClient = new Client({ |
| 79 | + ...documentInformation, |
| 80 | + url: app_url |
| 81 | + }) |
| 82 | + |
| 83 | + coolClient.onError((err) => { |
| 84 | + console.error(err?.error) |
| 85 | + coolClientErrors.add(1, { errorType: err?.error || 'unknown' }) |
| 86 | + }) |
| 87 | + |
| 88 | + await coolClient.establishSession() |
| 89 | + sleep(settings.sleep.after_request) |
| 90 | + |
| 91 | + // todo: move into pool |
| 92 | + const changes = [ |
| 93 | + 'textinput id=0 text=H', |
| 94 | + 'textinput id=0 text=e', |
| 95 | + 'textinput id=0 text=l', |
| 96 | + 'textinput id=0 text=l', |
| 97 | + 'textinput id=0 text=o', |
| 98 | + 'key type=input char=32 key=0', |
| 99 | + 'textinput id=0 text=w', |
| 100 | + 'textinput id=0 text=o', |
| 101 | + 'textinput id=0 text=r', |
| 102 | + 'textinput id=0 text=l', |
| 103 | + 'textinput id=0 text=d', |
| 104 | + 'key type=input char=33 key=0' |
| 105 | + ] |
| 106 | + |
| 107 | + await coolClient.makeChanges({ changes }) |
| 108 | + sleep(settings.sleep.after_request) |
| 109 | + |
| 110 | + coolClient.disconnect() |
| 111 | + sleep(settings.sleep.after_iteration) |
| 112 | +} |
| 113 | + |
| 114 | +export const open_change_save_010_teardown = ({ testRoot }: Environment): void => { |
| 115 | + const adminClient = clientFor({ userLogin: settings.admin.login, userPassword: settings.admin.password }) |
| 116 | + |
| 117 | + const waitForUnlock = () => { |
| 118 | + const { body } = adminClient.resource.getResourceProperties({ root: testRoot, resourcePath: settings.docx }) |
| 119 | + |
| 120 | + if(queryXml("$..['d:activelock']", body).length !== 0){ |
| 121 | + sleep(1) |
| 122 | + waitForUnlock() |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + waitForUnlock() |
| 127 | + |
| 128 | + adminClient.resource.deleteResource({ root: testRoot, resourcePath: settings.docx }) |
| 129 | +} |
| 130 | + |
| 131 | +export const setup = open_change_save_010_setup |
| 132 | +export default open_change_save_010 |
| 133 | +export const teardown = open_change_save_010_teardown |
0 commit comments