Skip to content

Commit

Permalink
Change: fix text by increase timeouts and run sync
Browse files Browse the repository at this point in the history
  • Loading branch information
NobleMajo committed May 27, 2024
1 parent a71f291 commit ab77c1f
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 70 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: NPM Publish

on:
push:
branches: [ "main" ]
paths:
- 'package.json'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm run test --if-present
- uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: dist

# publish-gpr:
# needs: build
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v3
# with:
# node-version: 20
# registry-url: https://npm.pkg.github.com/
# - uses: actions/download-artifact@v4
# with:
# name: build-artifacts
# path: dist
# - run: npm publish
# env:
# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- uses: actions/download-artifact@v4
with:
name: build-artifacts
path: dist
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
37 changes: 0 additions & 37 deletions .github/workflows/publish.yml

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cprox",
"description": "A easy to configure redirect, static serve, proxy and load balancer web server.",
"version": "1.9.9",
"version": "1.9.11",
"main": "dist/index.js",
"author": "NobleMajo",
"license": "MIT",
Expand All @@ -27,7 +27,8 @@
"tsc": "tsc -p tsconfig.json",
"start": "ts-node src/index.ts *=STATIC:/var/www/html --dry-run",
"exec": "node dist/index.js",
"test": "mocha --parallel --exit --require ts-node/register 'src/test/**/*.test.ts'",
"test": "mocha --exit --require ts-node/register 'src/test/**/*.test.ts'",
"test-parallel": "mocha --parallel --exit --require ts-node/register 'src/test/**/*.test.ts'",
"build": "npm run tsc",
"dev": "nodemon -w ./src -x \"npm run build; npm run test; npm run start\" --ext *.ts"
},
Expand All @@ -53,4 +54,4 @@
"serve-static": "^1.15.0",
"typenvy": "^1.5.15"
}
}
}
20 changes: 11 additions & 9 deletions src/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const defaultAsyncForkSettings: AsyncForkSettings = {
env: {},
spawnTimeout: 1000 * 4,
timeout: 1000 * 8,
closeTimeout: 1000 * 4,
closeTimeout: -1,
}

export async function asyncFork(
Expand Down Expand Up @@ -310,7 +310,7 @@ export function asyncSleep(millis: number): Promise<void> {

export async function startCprox(
args: string[],
timeoutMillis: number = 1000 * 8,
timeoutMillis: number,
checkIntervalMillis: number = 200,
): Promise<AsyncForkResult> {
if (timeoutMillis < 100) {
Expand All @@ -323,7 +323,7 @@ export async function startCprox(
__dirname + "/../index",
{
args: args,
timeout: defaultE2ETimeout - 5
timeout: timeoutMillis - 1000
}
)
await result.spawnPromise
Expand All @@ -333,7 +333,8 @@ export async function startCprox(
resolved = true
await result.close()
rej(new Error(
"Can't find started message!\n" +
"Can't find started message for:\n" +
args.join(" ") + "\n\n" +
(
result.output.length == 0 ?
"No error or standard output!" :
Expand All @@ -343,6 +344,7 @@ export async function startCprox(
}, timeoutMillis)
while (!resolved) {
await asyncSleep(checkIntervalMillis)

if (result.getStdOutput().includes("CProX| Server started!")) {
resolved = true
break
Expand All @@ -357,11 +359,11 @@ export async function startCprox(
return result
}

export const defaultE2ETimeout: number = 1000 * 16
export const defaultBeforeTimeout: number = 1000 * 8
export const defaultAfterTimeout: number = 1000 * 4
export const defaultCliTimeout: number = 1000 * 8
export const defaultTestTimeout: number = 1000 * 2
export const defaultE2ETimeout: number = 1000 * 60
export const defaultBeforeTimeout: number = 1000 * 40
export const defaultAfterTimeout: number = 1000 * 10
export const defaultCliTimeout: number = 1000 * 30
export const defaultTestTimeout: number = 1000 * 10

const defaultRequestTimeout: number = 140

Expand Down
13 changes: 8 additions & 5 deletions src/test/e2e/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect } from 'chai';
import 'mocha';
import { expect } from 'chai'
import {
defaultE2ETimeout, defaultCliTimeout,
asyncFork,
} from '../e2e'
defaultCliTimeout,
defaultE2ETimeout,
} from '../e2e';

describe('Live cli', function () {
this.timeout(defaultE2ETimeout)
Expand All @@ -14,7 +15,8 @@ describe('Live cli', function () {
const result = await asyncFork(
__dirname + "/../../index",
{
args: ["--help"]
args: ["--help"],
closeTimeout: defaultCliTimeout - 2000,
}
)
await result.spawnPromise
Expand Down Expand Up @@ -44,7 +46,8 @@ describe('Live cli', function () {
args: [
"--dry-run",
"*=STATIC:/var/www/html"
]
],
closeTimeout: defaultCliTimeout - 2000,
}
)
await result.spawnPromise
Expand Down
8 changes: 5 additions & 3 deletions src/test/e2e/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ describe('Live env', function () {
{
args: [
"--dry-run",
"*=STATIC:/var/www/html"
"*=STATIC:/var/www/html",
],
env: {
"VERBOSE": "true",
}
},
closeTimeout: defaultCliTimeout - 2000,
}
)
await result.spawnPromise
Expand Down Expand Up @@ -118,7 +119,8 @@ describe('Live env', function () {
"DRYRUN": "true",
"TRUST_ALL_CERTS": "true",
"SELF_SINGED_DOMAIN": "test.com",
}
},
closeTimeout: defaultCliTimeout - 2000,
}
)
await result.spawnPromise
Expand Down
7 changes: 5 additions & 2 deletions src/test/e2e/https-redirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { after, before } from 'mocha';
import fetch from 'node-fetch';
import {
AsyncForkResult, defaultAfterTimeout,
defaultBeforeTimeout, defaultE2ETimeout,
defaultBeforeTimeout,
defaultCliTimeout,
defaultE2ETimeout,
defaultFetchOptions,
defaultTestTimeout,
getRandomTestPort,
Expand All @@ -29,7 +31,7 @@ describe('Live E2E http to https redirect tests', function () {
"-s", "" + httpsPort,
"-b", "127.0.0.1",
"localhost=STATIC:" + __dirname + "/../html",
])
], defaultCliTimeout)
})

after(async function () {
Expand Down Expand Up @@ -58,6 +60,7 @@ describe('Live E2E http to https redirect tests', function () {

it('request without host', async function () {
this.timeout(defaultTestTimeout)

const resp = await fetch("http://127.0.0.1:" + httpPort, {
...defaultFetchOptions,
})
Expand Down
11 changes: 7 additions & 4 deletions src/test/e2e/load-balancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { after, before } from 'mocha';
import fetch, { Response } from "node-fetch";
import {
AsyncForkResult, defaultAfterTimeout,
defaultBeforeTimeout, defaultE2ETimeout,
defaultFetchOptions, defaultTestTimeout,
defaultBeforeTimeout,
defaultCliTimeout,
defaultE2ETimeout,
defaultFetchOptions,
defaultTestTimeout,
getLogMessage,
getRandomTestPort,
startCprox,
startCprox
} from '../e2e';

describe('Live E2E load balancer webserver tests', function () {
Expand All @@ -27,7 +30,7 @@ describe('Live E2E load balancer webserver tests', function () {
"-b", "127.0.0.1",
"localhost=REDIRECT:http://127.0.0.1:8080,http://127.0.0.1:8081,http://127.0.0.1:8082",
"test.com=REDIRECT:http://127.0.0.1:8080,http://127.0.0.1:8081,http://127.0.0.1:8082,http://127.0.0.1:8083",
])
], defaultCliTimeout)
})

after(async function () {
Expand Down
8 changes: 5 additions & 3 deletions src/test/e2e/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { after, before } from 'mocha';
import fetch, { Response } from 'node-fetch';
import {
AsyncForkResult, defaultAfterTimeout,
defaultBeforeTimeout, defaultE2ETimeout,
defaultBeforeTimeout,
defaultCliTimeout,
defaultE2ETimeout,
defaultFetchOptions,
defaultTestTimeout,
getRandomTestPort,
Expand All @@ -30,13 +32,13 @@ describe('Live E2E proxy webserver tests', function () {
"-b", "127.0.0.1",
"localhost=PROXY:http://127.0.0.1:" + port2,
"sub.com=PROXY:http://127.0.0.1:50404",
])
], defaultCliTimeout)
const p2 = startCprox([
"-p", "" + port2,
"-b", "127.0.0.1",
"localhost=STATIC:" + __dirname + "/../html",
"sub.com=STATIC:" + __dirname + "/../html/sub",
])
], defaultCliTimeout)

result2 = await p2
result = await p1
Expand Down
7 changes: 5 additions & 2 deletions src/test/e2e/static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { after, before } from 'mocha';
import fetch, { Response } from 'node-fetch';
import {
AsyncForkResult, defaultAfterTimeout,
defaultBeforeTimeout, defaultE2ETimeout,
defaultBeforeTimeout,
defaultCliTimeout,
defaultE2ETimeout,
defaultFetchOptions, defaultTestTimeout,
getRandomTestPort,
startCprox
Expand All @@ -20,12 +22,13 @@ describe('Live E2E static webserver tests', function () {
this.timeout(defaultBeforeTimeout)

port = getRandomTestPort()

result = await startCprox([
"-p", "" + port,
"-b", "127.0.0.1",
"localhost=STATIC:" + __dirname + "/../html",
"sub.com=STATIC:" + __dirname + "/../html/sub",
])
], defaultCliTimeout)
})

after(async function () {
Expand Down

0 comments on commit ab77c1f

Please sign in to comment.