Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for concurrent requests #37

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support symbolic executable links
Sometimes during testing it's useful to integrate the latest groove
executable build (stored currently in groove/build/grooveproxy)
into a downstream node package. Here we take care of resolving
symbolic links if they're found in the default bin.

This allows developer to do something like ln -s ~/grooveproxy/groove/build/grooveproxy ./node_modules/bin/grooveproxy
piercefreeman committed Nov 8, 2022
commit 03b65210dac9a77b7d3029e81abc8eb850d5a15b
3 changes: 3 additions & 0 deletions groove/build.sh
Original file line number Diff line number Diff line change
@@ -19,3 +19,6 @@ cp $rootDirectory/build/grooveproxy $rootDirectory/groove-python/groove/assets/g

# Manual Node install
cp $rootDirectory/build/grooveproxy $rootDirectory/groove-node/node_modules/.bin/grooveproxy

# Node build
(cd $rootDirectory/groove-node && npm run build)
6 changes: 5 additions & 1 deletion groove/groove-node/src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promisify } from 'util';
import { exec, spawn } from 'child_process';
import { stat } from 'fs/promises';
import { stat, realpath } from 'fs/promises';
import { readFileSync } from 'fs';
import { join } from 'path';
import { fetchWithTimeout, sleep, streamToBuffer } from './utilities';
@@ -95,6 +95,7 @@ export class Groove {
}

const exc = await this.getExecutablePath()
console.log(`Will launch groove executable: ${exc}`)
this.process = spawn(
exc,
Object.entries(parameters).reduce((previous: string[], [key, value] : [string, string | null]) => {
@@ -281,6 +282,9 @@ export class Groove {
const binDirectory = npmBin.stdout.trim();
this.executablePath = join(binDirectory, "grooveproxy");

// Resolve symbolic links
this.executablePath = await realpath(this.executablePath)

// Determine if the path exists, will raise an error if not
await stat(this.executablePath)

4 changes: 4 additions & 0 deletions groove/proxy/controller.go
Original file line number Diff line number Diff line change
@@ -159,13 +159,17 @@ func createController(recorder *Recorder, cache *Cache, dialerSession *DialerSes
dialerSession.DialerDefinitions = nil

if len(requests.Definitions) == 0 {
log.Println("No dialer definitions provided, using default dialer.")

// If no requests are provided, default to passing through everything
// so we're guaranteed to have one valid dialer
dialerSession.DialerDefinitions = append(
dialerSession.DialerDefinitions,
NewDialerDefinition(0, nil, nil),
)
} else {
log.Println("Setting dialer definitions...")

for _, request := range requests.Definitions {
var requestRequires *RequestRequiresDefinition = nil
var proxy *ProxyDefinition = nil
4 changes: 3 additions & 1 deletion groove/proxy/transport.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package main
import (
"crypto/tls"
"errors"
"fmt"
"log"
"net"
"net/http"
@@ -112,7 +113,8 @@ func (rt *CustomRoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
// Iterate the dialer until we hit on the correct value
dialerDefinition := rt.dialerSession.NextDialer(dialerContext)
if dialerDefinition == nil {
return nil, errors.New("Exhausted dialers")
log.Printf("Exhausted dialers - (tried: %d) (max allowed: %d)", len(rt.dialerSession.DialerDefinitions), rt.dialerSession.TotalTries)
return nil, fmt.Errorf("Exhausted dialers - (tried: %d) (max allowed: %d)", len(rt.dialerSession.DialerDefinitions), rt.dialerSession.TotalTries)
}

protocol, err := rt.solveProtocol(req, dialerDefinition)