From 76000f8fa11dde2f67efdb22a87c4644ea49f9eb Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 30 Jan 2021 19:58:15 +0100 Subject: :sparkles: Util --- src/test/db_benchmark.ts | 55 ------------------------------------------- src/test/db_test.ts | 9 ------- src/test/jwt.ts | 37 +++++++++++++++++++++++++++++ src/test/jwt2.ts | 8 +++++++ src/test/mongo_test.ts | 14 +++++++++++ src/test/rethink_benchmark.ts | 55 +++++++++++++++++++++++++++++++++++++++++++ src/test/rethink_test.ts | 34 ++++++++++++++++++++++++++ 7 files changed, 148 insertions(+), 64 deletions(-) delete mode 100644 src/test/db_benchmark.ts delete mode 100644 src/test/db_test.ts create mode 100644 src/test/jwt.ts create mode 100644 src/test/jwt2.ts create mode 100644 src/test/mongo_test.ts create mode 100644 src/test/rethink_benchmark.ts create mode 100644 src/test/rethink_test.ts (limited to 'src/test') diff --git a/src/test/db_benchmark.ts b/src/test/db_benchmark.ts deleted file mode 100644 index 74623e06..00000000 --- a/src/test/db_benchmark.ts +++ /dev/null @@ -1,55 +0,0 @@ -// @ts-nocheck -import { r } from "rethinkdb-ts"; -import faker from "faker"; -import cluster from "cluster"; -import { performance } from "perf_hooks"; - -console.log("starting"); - -if (cluster.isMaster) { - for (var i = 0; i < 1; i++) { - cluster.fork(); - } - console.log("all nodes started"); -} - -if (cluster.isWorker) { - const inserts = []; - - for (let i = 0; i < 100; i++) { - inserts.push({ - color: faker.commerce.color(), - department: faker.commerce.department(), - price: faker.commerce.price(), - product: faker.commerce.product(), - productAdjective: faker.commerce.productAdjective(), - productName: faker.commerce.productName(), - productMaterial: faker.commerce.productMaterial(), - productDescription: faker.commerce.productDescription(), - }); - } - - async function main(connection) { - const start = performance.now(); - await r - .db("test") - .table("test") - .nth(Math.floor(Math.random() * 300000)) - .run(connection); - const end = performance.now(); - // console.log(end - start); - - // await main(connection); - setTimeout(main.bind(null, connection)); - } - - (async () => { - const threads = 30; - - for (var i = 0; i < threads; i++) { - setTimeout(async () => { - main(await r.connect({ port: 28015, host: "192.168.178.122" })); - }); - } - })(); -} diff --git a/src/test/db_test.ts b/src/test/db_test.ts deleted file mode 100644 index 9d4b0072..00000000 --- a/src/test/db_test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { r } from "rethinkdb-ts"; - -async function main() { - const connection = await r.connect({ port: 28015, host: "192.168.178.122" }); - - r.db("test"); -} - -main(); diff --git a/src/test/jwt.ts b/src/test/jwt.ts new file mode 100644 index 00000000..bdad513b --- /dev/null +++ b/src/test/jwt.ts @@ -0,0 +1,37 @@ +const jwa = require("jwa"); + +var STR64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".split(""); + +function base64url(string: string, encoding: string) { + // @ts-ignore + return Buffer.from(string, encoding).toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); +} + +function to64String(input: number, current = ""): string { + if (input < 0 && current.length == 0) { + input = input * -1; + } + var modify = input % 64; + var remain = Math.floor(input / 64); + var result = STR64[modify] + current; + return remain <= 0 ? result : to64String(remain, result); +} + +function to64Parse(input: string) { + var result = 0; + var toProc = input.split(""); + var e; + for (e in toProc) { + result = result * 64 + STR64.indexOf(toProc[e]); + } + return result; +} + +// @ts-ignore +const start = `${base64url("311129357362135041")}.${to64String(Date.now())}`; +const signature = jwa("HS256").sign(start, `test`); +const token = `${start}.${signature}`; +console.log(token); + +// MzExMTI5MzU3MzYyMTM1MDQx.XdQb_rA.907VgF60kocnOTl32MSUWGSSzbAytQ0jbt36KjLaxuY +// MzExMTI5MzU3MzYyMTM1MDQx.XdQbaPy.4vGx4L7IuFJGsRe6IL3BeybLIvbx4Vauvx12pwNsy2U diff --git a/src/test/jwt2.ts b/src/test/jwt2.ts new file mode 100644 index 00000000..ca73a035 --- /dev/null +++ b/src/test/jwt2.ts @@ -0,0 +1,8 @@ +import jwt from "jsonwebtoken"; + +// console.log(jwt.sign("test", "test")); + +jwt.verify(`${"2WmFS_EAdYFCBOFM9pVPo9g4bpuI2I9U_JGTCfrx7Tk".repeat(1000000)}`, "test", (err, decoded) => { + if (err) console.error(err); + console.log(decoded); +}); diff --git a/src/test/mongo_test.ts b/src/test/mongo_test.ts new file mode 100644 index 00000000..c4b3ec37 --- /dev/null +++ b/src/test/mongo_test.ts @@ -0,0 +1,14 @@ +import mongoose from "mongoose"; + +async function main() { + const mongoConnection = await mongoose.createConnection( + "mongodb://localhost:27017/lambert?readPreference=secondaryPreferred", + { + useNewUrlParser: true, + useUnifiedTopology: false, + } + ); + console.log("connected"); +} + +main(); diff --git a/src/test/rethink_benchmark.ts b/src/test/rethink_benchmark.ts new file mode 100644 index 00000000..74623e06 --- /dev/null +++ b/src/test/rethink_benchmark.ts @@ -0,0 +1,55 @@ +// @ts-nocheck +import { r } from "rethinkdb-ts"; +import faker from "faker"; +import cluster from "cluster"; +import { performance } from "perf_hooks"; + +console.log("starting"); + +if (cluster.isMaster) { + for (var i = 0; i < 1; i++) { + cluster.fork(); + } + console.log("all nodes started"); +} + +if (cluster.isWorker) { + const inserts = []; + + for (let i = 0; i < 100; i++) { + inserts.push({ + color: faker.commerce.color(), + department: faker.commerce.department(), + price: faker.commerce.price(), + product: faker.commerce.product(), + productAdjective: faker.commerce.productAdjective(), + productName: faker.commerce.productName(), + productMaterial: faker.commerce.productMaterial(), + productDescription: faker.commerce.productDescription(), + }); + } + + async function main(connection) { + const start = performance.now(); + await r + .db("test") + .table("test") + .nth(Math.floor(Math.random() * 300000)) + .run(connection); + const end = performance.now(); + // console.log(end - start); + + // await main(connection); + setTimeout(main.bind(null, connection)); + } + + (async () => { + const threads = 30; + + for (var i = 0; i < threads; i++) { + setTimeout(async () => { + main(await r.connect({ port: 28015, host: "192.168.178.122" })); + }); + } + })(); +} diff --git a/src/test/rethink_test.ts b/src/test/rethink_test.ts new file mode 100644 index 00000000..d1470515 --- /dev/null +++ b/src/test/rethink_test.ts @@ -0,0 +1,34 @@ +import { r } from "rethinkdb-ts"; + +async function main() { + const connection = await r.connect({ port: 28015 }); + + const db = r.db("test"); + const cursor = await db + .table("guilds") + .get(0) + .changes({ squash: true }) + .map(function (row) { + return row("old_val") + .keys() + .setUnion(row("new_val").keys()) + .concatMap(function (key) { + return r.branch( + row("old_val")(key).ne(row("new_val")(key)).default(true), + [[key, row("new_val")(key).default(null)]], + [] + ); + }) + .coerceTo("object"); + }) + .run(connection); + + console.log("each"); + cursor.each(function (err, row) { + if (err) throw err; + console.log(row); + }); + console.log("eachend"); +} + +main(); -- cgit 1.5.1