Skip to content

Commit

Permalink
Merge branch 'main' into chore/git-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Jul 6, 2023
2 parents 8971f05 + 484fd71 commit f49294b
Show file tree
Hide file tree
Showing 142 changed files with 9,820 additions and 6,158 deletions.
36 changes: 20 additions & 16 deletions examples/artillery-engine-example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ExampleEngine {
// For each scenario in the script using this engine, Artillery calls this function
// to create a VU function
createScenario(scenarioSpec, ee) {
const tasks = scenarioSpec.flow.map(rs => this.step(rs, ee));
const tasks = scenarioSpec.flow.map((rs) => this.step(rs, ee));

return function scenario(initialContext, callback) {
ee.emit('started');
Expand All @@ -48,16 +48,14 @@ class ExampleEngine {

const steps = [vuInit].concat(tasks);

A.waterfall(
steps,
function done(err, context) {
if (err) {
debug(err);
}
A.waterfall(steps, function done(err, context) {
if (err) {
debug(err);
}

return callback(err, context);
});
}
return callback(err, context);
});
};
}

// This is a convenience function where we delegate common actions like loop, log, and think,
Expand All @@ -66,14 +64,16 @@ class ExampleEngine {
const self = this;

if (rs.loop) {
const steps = rs.loop.map(loopStep => this.step(loopStep, ee));
const steps = rs.loop.map((loopStep) => this.step(loopStep, ee));

return this.helpers.createLoopWithCount(rs.count || -1, steps, {});
}

if (rs.log) {
return function log(context, callback) {
return process.nextTick(function () { callback(null, context); });
return process.nextTick(function () {
callback(null, context);
});
};
}

Expand All @@ -85,7 +85,9 @@ class ExampleEngine {
return function (context, callback) {
let func = self.script.config.processor[rs.function];
if (!func) {
return process.nextTick(function () { callback(null, context); });
return process.nextTick(function () {
callback(null, context);
});
}

return func(context, ee, function () {
Expand All @@ -99,7 +101,10 @@ class ExampleEngine {
//
if (rs.doSomething) {
return function example(context, callback) {
console.log('doSomething action with id:', self.helpers.template(rs.doSomething.id, context, true));
console.log(
'doSomething action with id:',
self.helpers.template(rs.doSomething.id, context, true)
);
console.log('target is:', self.target);

// Emit a metric to count the number of example actions performed:
Expand All @@ -113,9 +118,8 @@ class ExampleEngine {
//
return function doNothing(context, callback) {
return callback(null, context);
}
};
}
}

module.exports = ExampleEngine;

22 changes: 12 additions & 10 deletions examples/artillery-engine-example/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ const script = {
mandatoryString: 'hello-world'
}
},
scenarios: [{
name: 'test scenario',
engine: 'example',
flow: [
{
doSomething: {
id: 123
scenarios: [
{
name: 'test scenario',
engine: 'example',
flow: [
{
doSomething: {
id: 123
}
}
}
]
}]
]
}
]
};

test('Engine interface', function (t) {
Expand Down
11 changes: 8 additions & 3 deletions examples/artillery-plugin-hello-world/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ function ArtilleryHelloWorldPlugin(script, events) {
// Create processor object if needed to hold our custom function:
script.config.processor = script.config.processor || {};
// Add our custom function:
script.config.processor['pluginHelloWorldBeforeRequestHook'] = function(req, vuContext, events, next) {
script.config.processor['pluginHelloWorldBeforeRequestHook'] = function (
req,
vuContext,
events,
next
) {
// This a beforeRequest handler function:
// https://artillery.io/docs/guides/guides/http-reference.html#beforeRequest

console.log(self.greeting); // print greeting
events.emit('counter', 'greeting_count', 1); // increase custom counter
return next(); // the hook is done, go on to the next one (or let Artillery make the request)
}
};
// Attach the function to every scenario as a scenario-level hook:
script.scenarios.forEach((scenario) => {
scenario.beforeRequest = scenario.beforeRequest || [];
Expand All @@ -57,7 +62,7 @@ function ArtilleryHelloWorldPlugin(script, events) {
// Artillery will call this before it exits to give plugins
// a chance to clean up, e.g. by flushing any in-flight data,
// writing something to disk etc.
ArtilleryHelloWorldPlugin.prototype.cleanup = function(done) {
ArtilleryHelloWorldPlugin.prototype.cleanup = function (done) {
debug('cleaning up');
done(null);
};
2 changes: 1 addition & 1 deletion examples/browser-load-testing-playwright/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ async function multistepWithCustomMetrics(page, userContext, events) {
module.exports = {
cloudWaitlistSignupFlow,
checkPage,
multistepWithCustomMetrics,
multistepWithCustomMetrics
};
8 changes: 4 additions & 4 deletions examples/file-uploads/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const app = express();
const upload = require("multer")({ dest: "uploads/", preservePath: true });
const upload = require('multer')({ dest: 'uploads/', preservePath: true });
const port = 3000;

app.post("/upload", upload.single("document"), (req, res) => {
app.post('/upload', upload.single('document'), (req, res) => {
const { originalname, mimetype, size } = req.file;
res.json({ originalname, mimetype, size });
})
});

app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`);
Expand Down
58 changes: 33 additions & 25 deletions examples/functional-testing-with-expect-plugin/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const express = require("express");
const express = require('express');
const app = express();
const port = 3000;

Expand All @@ -7,45 +7,53 @@ const db = new sqlite3.Database(':memory:');

app.use(express.json());

app.post("/users", (req, res) => {
if (req.body.username === "") {
res.status(422).send({ error: "username is missing"});
app.post('/users', (req, res) => {
if (req.body.username === '') {
res.status(422).send({ error: 'username is missing' });
return;
}

db.run("INSERT INTO users (username) VALUES (?)", [req.body.username], function(err) {
if (err === null) {
res.status(201).send({ id: this.lastID, username: req.body.username });
} else {
res.status(500).send(err);
db.run(
'INSERT INTO users (username) VALUES (?)',
[req.body.username],
function (err) {
if (err === null) {
res.status(201).send({ id: this.lastID, username: req.body.username });
} else {
res.status(500).send(err);
}
}
});
);
});

app.get("/users/:id", (req, res) => {
db.get("SELECT * FROM users WHERE id = ?", [req.params.id], function(err, row) {
if (err !== null) {
res.status(500).send(err);
return
}
app.get('/users/:id', (req, res) => {
db.get(
'SELECT * FROM users WHERE id = ?',
[req.params.id],
function (err, row) {
if (err !== null) {
res.status(500).send(err);
return;
}

if (row === undefined) {
res.status(404).send({ error: "User not found" });
} else {
res.status(200).send(row);
if (row === undefined) {
res.status(404).send({ error: 'User not found' });
} else {
res.status(200).send(row);
}
}
});
);
});

app.delete("/users/:id", (req, res) => {
db.run("DELETE FROM users WHERE id = ?", [req.params.id], function(err) {
app.delete('/users/:id', (req, res) => {
db.run('DELETE FROM users WHERE id = ?', [req.params.id], function (err) {
if (err !== null) {
res.status(500).send(err);
return
return;
}

if (this.changes === 0) {
res.status(404).send({ error: "User not found" });
res.status(404).send({ error: 'User not found' });
} else {
res.sendStatus(204);
}
Expand Down
10 changes: 5 additions & 5 deletions examples/graphql-api-server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const typeDefs = gql`
}
type Query {
users: [User],
users: [User]
user(id: ID!): User
userByUsername(username: String!): User
userByEmail(username: String!): User
Expand All @@ -38,26 +38,26 @@ const resolvers = {
user: async (_, { id }) => {
return await prisma.user.findUnique({
where: { id: parseInt(id) }
})
});
},

userByEmail: async (_, { email }) => {
return await prisma.user.findUnique({
where: { email }
})
});
},

userByUsername: async (_, { username }) => {
return await prisma.user.findUnique({
where: { username }
})
});
}
},

Mutation: {
createUser: async (_, { input }) => {
return await prisma.user.create({
data: input,
data: input
});
},

Expand Down
28 changes: 15 additions & 13 deletions examples/http-set-custom-header/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ const https = require('https');
function setCustomHeader(req, userContext, ee, next) {
let data = '';

https.get('https://api.artillery.io/v1/dino', (res) => {
res.on('data', (d) => {
data += d;
});
https
.get('https://api.artillery.io/v1/dino', (res) => {
res.on('data', (d) => {
data += d;
});

res.on('end', () => {
// Extract a string composed of letters + spaces + punctuation:
const val = data.match(/^<([A-Za-z\!\s]+)/m)[1].trim();
// Use that as the value of our custom header:
req.headers['x-dino'] = val;
return next();
res.on('end', () => {
// Extract a string composed of letters + spaces + punctuation:
const val = data.match(/^<([A-Za-z\!\s]+)/m)[1].trim();
// Use that as the value of our custom header:
req.headers['x-dino'] = val;
return next();
});
})
.on('error', (e) => {
return next(e);
});
}).on('error', (e) => {
return next(e);
});
}

module.exports = {
Expand Down
11 changes: 4 additions & 7 deletions examples/http-socketio-server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
es2021: true
},
extends: [
'airbnb-base',
],
extends: ['airbnb-base'],
parserOptions: {
ecmaVersion: 12,
},
rules: {
ecmaVersion: 12
},
rules: {}
};
1 change: 0 additions & 1 deletion examples/http-socketio-server/data/movies.json
Original file line number Diff line number Diff line change
Expand Up @@ -1350,4 +1350,3 @@
"runningTimeMin": 100
}
]

11 changes: 4 additions & 7 deletions examples/k8s-testing-with-kubectl-artillery/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
es2021: true
},
extends: [
'airbnb-base',
],
extends: ['airbnb-base'],
parserOptions: {
ecmaVersion: 12,
},
rules: {
ecmaVersion: 12
},
rules: {}
};
Original file line number Diff line number Diff line change
Expand Up @@ -1350,4 +1350,3 @@
"runningTimeMin": 100
}
]

Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,4 @@
"uid": "hsGnZJunz",
"version": 11,
"weekStart": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,4 @@
"uid": "siOy7cXnk",
"version": 22,
"weekStart": ""
}
}
Loading

0 comments on commit f49294b

Please sign in to comment.