Created
July 19, 2022 15:43
-
-
Save samirpatel-slingshot/656308202dda95249b77dcb3b01e215c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { check, sleep } from 'k6' | |
import stomp from 'k6/x/stomp' | |
import http from 'k6/http' | |
// import { accessToken } from './auth.js'; | |
import ws from 'k6/ws' | |
import { randomString, randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js' | |
import { Httpx, Request, Get, Post } from 'https://jslib.k6.io/httpx/0.0.2/index.js' | |
let sessionDuration = randomIntBetween(5000, 60000) // user session between 5s and 1m | |
//defining auth credentials | |
const CLIENT_ID = __ENV.CLIENT_ID | |
const CLIENT_SECRET = __ENV.CLIENT_SECRET | |
let session = new Httpx({ | |
baseURL: 'https://slingshotorbitallabs.us.auth0.com', | |
}) | |
let client = null | |
//TODO setup VU options & thresholds | |
// export let options = { | |
// stages: [ | |
// { duration: '2m', target: 40 }, // ramp up to 40 users (avg classroom size) | |
// { duration: '2h', target: 40 }, // stay at 40 for 2 hours (avg length of lecture session) | |
// { duration: '2m', target: 0 }, // scale down (optional) | |
// ], | |
// thresholds: { | |
// errors: [ "rate<1" ] | |
// }, | |
/* ext: { | |
loadimpact: { | |
projectId: 3588513, | |
name: "Laboratory Propagation Tests", | |
distribution: { | |
scenarioLabel1: { loadZone: "amazon:us:ashburn", percent: 50 }, | |
scenarioLabel2: { loadZone: "amazon:us:portland", percent: 50} | |
} | |
} | |
} | |
}; */ | |
//TODO add sleep times | |
//Establish connection with /propagation | |
export default function () { | |
const data = { | |
grant_type: 'password', | |
username: __ENV.USER, | |
password: __ENV.PASS, | |
scope: 'openid', | |
client_id: CLIENT_ID, | |
client_secret: CLIENT_SECRET, | |
audience: 'https://orbital-lab.service.govspctrndev.ssa', | |
} | |
let res = http.post('https://slingshotorbitallabs.us.auth0.com/oauth/token', JSON.stringify(data), { | |
headers: { 'Content-Type': 'application/json' }, | |
}) | |
let authToken = res.json('access_token') | |
console.log(authToken) | |
// const params = { | |
// headers: , | |
// } | |
const client = stomp.connect({ | |
headers: { | |
Authorization: `Bearer ${authToken}`, | |
userprofile: 'Emily McCue,e.mccue+labtest@slingshotaerospace.com', | |
}, | |
protocol: 'wss', | |
addr: 'lab-apitest.spctrndev.ssa.zone', | |
path: '/propagation', | |
timeout: '5s', | |
heartbeat: { | |
incoming: '3s', | |
outgoing: '3s', | |
}, | |
message_send_timeout: '5s', | |
receipt_timeout: '5s', | |
tls: true, | |
}) | |
//TODO figure out status codes for websockets (?) and figure out a load safe "retry" or wait | |
//sleep(5); | |
//subscribe to client | |
let subscription = client.subscribe('/secured/user/queue/specific-user53f24d5f-a5e2-49e8-9d61-b4c0d00cc84b') //TODO retrieve this automatically | |
//console.log(subscription.read().string()); | |
// console.log('here'); | |
//sleep(3); | |
//TODO send multiple messages | |
//propagation msg for 1 GEO orbit period (24 hours) | |
client.send( | |
`/app/propagation`, | |
`text/plain`, | |
`{"msgType":"propagate","data":{"stepSize":287.2120610050841,"orbits":[{"id":386,"perturbations":{"j2":false,"drag":false,"solarRadiation":false},"startTimestamp":"2021-03-10T15:20:00.000Z","endTimestamp":"2021-03-11T15:20:00.000Z","orbitType":"COE","orbit":{"argumentOfPeriapsis":0,"eccentricity":0,"epoch":1649863201576,"inclination":0,"rightAscensionOfAscendingNode":0,"semiMajorAxis":42164,"trueAnomaly":0,"mass":5}}]}}` //payload | |
) | |
const subscribeOpts = { | |
ack: 'client', | |
} | |
// read the message | |
const msg = subscription.read() | |
//show the message as a string | |
console.log('msg', msg.string()) | |
check(client, { 'Connected successfully': (r) => r && r.status === 101 }) | |
// ack the message | |
client.ack(msg) | |
// unsubscribe from destination | |
subscription.unsubscribe() | |
client.disconnect() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment