Skip to content

Commit

Permalink
Use ddapm-test-agent from environment if available
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller committed Jul 2, 2024
1 parent a92475a commit cc5f5b3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '>=3.9 <3.13'
cache: pip
cache-dependency-path: _integration-tests/utils/agent/requirements.txt
- name: Install python dependencies
run: pip install -r _integration-tests/utils/agent/requirements.txt
- name: Build orchestrion binary
run: go build -cover -covermode=atomic -coverpkg="./..." -o="bin/orchestrion.exe" .
- name: Run Integration Tests
Expand Down
41 changes: 25 additions & 16 deletions _integration-tests/utils/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,41 @@ func New(t *testing.T) (*MockAgent, error) {
agent MockAgent
err error
)
if agent.virtualEnv, err = os.MkdirTemp("", "orchestrion-integ-venv-*"); err != nil {
return nil, err
}
t.Logf("Creating Python venv at %q...\n", agent.virtualEnv)
if err = exec.Command("python3", "-m", "venv", agent.virtualEnv).Run(); err != nil {
return nil, err
}
venvBin := filepath.Join(agent.virtualEnv, "bin")
if runtime.GOOS == "windows" {
venvBin = filepath.Join(agent.virtualEnv, "Scripts")
}

t.Logf("Installing ddapm-test-agent in venv...\n")
if err = exec.Command(filepath.Join(venvBin, "pip"), "install", "ddapm-test-agent").Run(); err != nil {
return nil, err
ddapmTestAgent, _ := exec.LookPath("ddapm-test-agent")
if ddapmTestAgent == "" {
t.Log("No ddapm-test-agent found in $PATH, installing into a python venv...")
if agent.virtualEnv, err = os.MkdirTemp("", "orchestrion-integ-venv-*"); err != nil {
return nil, err
}
t.Logf("Creating Python venv at %q...\n", agent.virtualEnv)
if err = exec.Command("python3", "-m", "venv", agent.virtualEnv).Run(); err != nil {
return nil, err
}
venvBin := filepath.Join(agent.virtualEnv, "bin")
if runtime.GOOS == "windows" {
venvBin = filepath.Join(agent.virtualEnv, "Scripts")
}

t.Logf("Installing requirements in venv...\n")
_, thisFile, _, _ := runtime.Caller(0)
thisDir := filepath.Dir(thisFile)
if err = exec.Command(filepath.Join(venvBin, "pip"), "install", "-r", filepath.Join(thisDir, "requirements.txt")).Run(); err != nil {
return nil, err
}

ddapmTestAgent = filepath.Join(venvBin, "ddapm-test-agent")
}

if agent.port, err = getFreePort(); err != nil {
return nil, err
}
t.Logf("Starting ddapm-test-agent on port %d\n", agent.port)
t.Logf("Starting %s on port %d\n", ddapmTestAgent, agent.port)
var ctx context.Context
ctx, agent.processCancel = context.WithCancel(context.Background())
agent.process = exec.CommandContext(
ctx,
filepath.Join(venvBin, "ddapm-test-agent"),
ddapmTestAgent,
fmt.Sprintf("--port=%d", agent.port),
)
if err = agent.process.Start(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions _integration-tests/utils/agent/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ddapm-test-agent~=1.17.0

0 comments on commit cc5f5b3

Please sign in to comment.