Skip to content

Commit

Permalink
pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
recap committed Aug 12, 2024
1 parent bd075d1 commit 36a3479
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ pm2 restart server
```

## Load testing

Under `server_test` there are scripts to stress test the server. Refer to the [README](./server_test/README.md) for further information.

## API documentation
Expand Down
17 changes: 11 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const app = express()
const server = http.createServer(app)
const io = socketIO(server)
const fs = require("fs")
const path = require('path');
const path = require("path")
const CryptoJS = require("crypto-js")
const Queue = require("./local-queue.js")
const db = require("./postgres-db")
Expand Down Expand Up @@ -41,16 +41,15 @@ const port = options.port || "8060"
const userDbFile = options.dbFile || "./data/userdb.sqlite"

// Define the path for the 'data' folder
const dataFolderPath = path.join(__dirname, 'data');
const dataFolderPath = path.join(__dirname, "data")

// Check if the 'data' folder exists
// and create one if not.
if (!fs.existsSync(dataFolderPath)) {
// Create the 'data' folder if it doesn't exist
fs.mkdirSync(dataFolderPath, { recursive: true });
// Create the 'data' folder if it doesn't exist
fs.mkdirSync(dataFolderPath, { recursive: true })
}


/**
*
* @type {Set<string>}
Expand Down Expand Up @@ -883,7 +882,13 @@ async function main() {
if (user.state == "redirected") {
// Something went wrong to get here
// Try starting game with one user
startGame([compoundKey], [user.experimentUrl], null, user.groupId, user.server)
startGame(
[compoundKey],
[user.experimentUrl],
null,
user.groupId,
user.server,
)
return
}
if (user.state === "inoTreePages") {
Expand Down
6 changes: 4 additions & 2 deletions server_test/test_user_flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ const experimentId = options.experimentId || "DropOutTest"
const url = `http://${host}:${port}`
const virtUsers = {}

console.log(`Trying server url: ${url} from id ${start} to ${start + maxUsers} for experiment ${experimentId}.`)
console.log(
`Trying server url: ${url} from id ${start} to ${start + maxUsers} for experiment ${experimentId}.`,
)

function runTest() {
for (let i = start; i < (start + maxUsers); i++) {
for (let i = start; i < start + maxUsers; i++) {
const id = i
vu = new VirtualUser(id, experimentId, url)
virtUsers[id] = vu
Expand Down
39 changes: 18 additions & 21 deletions server_test/virtual-user-ws.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
const io = require("socket.io-client")
const CryptoJS = require("crypto-js")
const path = require('path')
const fs = require('fs')
const dotenv = require('dotenv')

const path = require("path")
const fs = require("fs")
const dotenv = require("dotenv")

// Function to search for .env file in current or parent directory
function findEnvFile() {
let currentDir = process.cwd();
let currentDir = process.cwd()

while (true) {
const envPath = path.join(currentDir, '.env');
if (fs.existsSync(envPath)) {
return envPath;
}
const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
break; // Reached the root directory
}
currentDir = parentDir;
while (true) {
const envPath = path.join(currentDir, ".env")
if (fs.existsSync(envPath)) {
return envPath
}
const parentDir = path.dirname(currentDir)
if (parentDir === currentDir) {
break // Reached the root directory
}
currentDir = parentDir
}

return null; // .env file not found
return null // .env file not found
}

// Load environment variables
const envFilePath = findEnvFile();
const envFilePath = findEnvFile()
if (envFilePath) {
dotenv.config({ path: envFilePath });
dotenv.config({ path: envFilePath })
} else {
console.warn('.env file not found in current or parent directory');
console.warn(".env file not found in current or parent directory")
}



const secretKey = process.env.SECRET_KEY

class VirtualUser {
Expand Down

0 comments on commit 36a3479

Please sign in to comment.