Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pogilvie/sfdx
Browse files Browse the repository at this point in the history
  • Loading branch information
pogilvieCB committed Apr 29, 2021
2 parents 46db089 + b63cb47 commit a5f1d72
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Makefile
Expand Up @@ -47,4 +47,13 @@ ui:
bin/run ui:call -s Case -p Foods__c -r 012610000002pGnAAI -u $(user)

ui-cb:
bin/run ui:call -s Case -p s_Sub_category__c -r 0126A000000VHhkQAG -u $(user)
bin/run ui:call -s Case -p s_Sub_category__c -r 0126A000000VHhkQAG -u $(user)
bin/run ui:call -s Object_A__c -p Foods__c -r 012610000002pGnAAI -u $(user)

#
# GEN LOAD GENERATOR
#
# Requires scatch org 'sim' be brought up and populated
#
gen:
bin/run gen:run -i 5 -e /sim -u sim
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -11,10 +11,12 @@
"@salesforce/command": "^2",
"@salesforce/core": "^2",
"@types/columnify": "^1.5.0",
"@types/p-queue": "^3.2.1",
"columnify": "^1.5.4",
"cometd": "^7.0.1",
"cometd-nodejs-client": "^1.3.0",
"mongodb": "^3.6.5",
"p-queue": "6.6.2",
"tslib": "^1"
},
"devDependencies": {
Expand All @@ -34,7 +36,7 @@
"typescript": "~3.3"
},
"engines": {
"node": ">=8.0.0"
"node": ">=12"
},
"files": [
"/lib",
Expand Down
69 changes: 69 additions & 0 deletions src/commands/gen/run.ts
@@ -0,0 +1,69 @@
import { flags, SfdxCommand } from '@salesforce/command';
import { AnyJson } from '@salesforce/ts-types';
import PQueue from 'p-queue'

function *example() : Generator<any> {
let count = 0
while (1) {
yield {
msg: "Hello, World!",
value: count++
}
}
}

export default class Run extends SfdxCommand {

protected static requiresUsername = true;
protected static requiresProject = false;
public static description = 'Test performance / correctness of a apex rest endpoint'
public static examples = [ ]
protected static flagsConfig = {
endpoint: flags.string( { char: 'e', description: 'API name of sobject', required: true } ),
iterations: flags.integer( { char: 'i', description: 'iterations', default: 5 } ),
interval: flags.integer( {char: 't', description: 'interval time in msec', default: 1000}),
concurrency: flags.integer( {char: 'c', description: 'number of requests per interval', default: 5})
};

public async run(): Promise<AnyJson> {
console.log(this.flags)

const queue = new PQueue({
concurrency: this.flags.concurrency,
intervalCap: this.flags.concurrency,
interval: this.flags.interval,
carryoverConcurrencyCount: true
});

const iterator = example()

console.log('Hello, World!')

let min = 1000000000, max = 0, total = 0, successes = 0, failures = 0

const c = this.org.getConnection()

for (let i = 0; i < this.flags.iterations; i++) {
queue.add( async () => {
console.log(`start ${i}`)
const start = Date.now()
try {
const result = await c.apex.post(this.flags.endpoint, iterator.next().value)
successes += 1
} catch (e) {
failures += 1
console.log(`Failed ${i}:`, e)
} finally {
const delta = Date.now() - start
total += delta
min = (delta < min) ? delta : min
max = (delta > max) ? delta : max
console.log(`end ${i} ${delta}`)
}
})
}
queue.onIdle().then( () => console.log(`min:${min} max:${max} ave:${total/this.flags.iterations} succ:${successes} fail:${failures}`) )

return <AnyJson><unknown>null
}
}
40 changes: 40 additions & 0 deletions yarn.lock
Expand Up @@ -369,6 +369,13 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.8.tgz"
integrity sha512-I4+DbJEhLEg4/vIy/2gkWDvXBOOtPKV9EnLhYjMoqxcRW+TTZtUftkHktz/a8suoD5mUL7m6ReLrkPvSsCQQmw==

"@types/p-queue@^3.2.1":
version "3.2.1"
resolved "https://registry.yarnpkg.com/@types/p-queue/-/p-queue-3.2.1.tgz#614957d9ed05cf6e02d08ed8f09041c4d100ef70"
integrity sha512-tgAdn5zEs05NuHzOyRM34cMO0rczStphR/kLo/ZJwwwJ5S2+QVxwA6gST3vDHWPB1oDfUuT6wOouhJvJkBCA0w==
dependencies:
p-queue "*"

"@types/sinon@*":
version "7.0.12"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-7.0.12.tgz"
Expand Down Expand Up @@ -1245,6 +1252,11 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz"
integrity sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=

eventemitter3@^4.0.4, eventemitter3@^4.0.7:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

execa@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.10.0.tgz"
Expand Down Expand Up @@ -2779,6 +2791,34 @@ p-locate@^3.0.0:
dependencies:
p-limit "^2.0.0"

p-queue@*:
version "7.1.0"
resolved "https://registry.yarnpkg.com/p-queue/-/p-queue-7.1.0.tgz#c2bb28f8dc0ebf3fadb985b8706cf2ce5fe5f275"
integrity sha512-V+0vPJbhYkBqknPp0qnaz+dWcj8cNepfXZcsVIVEHPbFQXMPwrzCNIiM4FoxGtwHXtPzVCPHDvqCr1YrOJX2Gw==
dependencies:
eventemitter3 "^4.0.7"
p-timeout "^5.0.0"

p-queue@6.6.2:
version "6.6.2"
resolved "https://registry.yarnpkg.com/p-queue/-/p-queue-6.6.2.tgz#2068a9dcf8e67dd0ec3e7a2bcb76810faa85e426"
integrity sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==
dependencies:
eventemitter3 "^4.0.4"
p-timeout "^3.2.0"

p-timeout@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-3.2.0.tgz#c7e17abc971d2a7962ef83626b35d635acf23dfe"
integrity sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==
dependencies:
p-finally "^1.0.0"

p-timeout@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-5.0.0.tgz#0f5dc08422e7243f8317669c461734cd1257a8dc"
integrity sha512-z+bU/N7L1SABsqKnQzvAnINgPX7NHdzwUV+gHyJE7VGNDZSr03rhcPODCZSWiiT9k+gf74QPmzcZzqJRvxYZow==

p-try@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz"
Expand Down

0 comments on commit a5f1d72

Please sign in to comment.