Skip to content

Commit

Permalink
Merge branch 'ai-video' into 3185-unify-pipeline-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko authored Oct 22, 2024
2 parents 421aa2c + ff1f517 commit 6f40b18
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
id: go
uses: actions/setup-go@v5
with:
go-version: 1.21.5
go-version: 1.23.2
cache: true
cache-dependency-path: go.sum

Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
id: go
uses: actions/setup-go@v5
with:
go-version: 1.21.5
go-version: 1.23.2
cache: true
cache-dependency-path: go.sum

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
id: go
uses: actions/setup-go@v5
with:
go-version: 1.21.5
go-version: 1.23.2
cache: true
cache-dependency-path: go.sum

Expand Down
2 changes: 1 addition & 1 deletion cmd/livepeer/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
if n.OrchSecret == "" {
if *cfg.AIModels != "" {
glog.Info("Running an orchestrator in AI External Container mode")
} else if n.OrchSecret == "" {
} else {
glog.Exit("Running an orchestrator requires an -orchSecret for standalone mode or -transcoder for orchestrator+transcoder mode")
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func ParseAIModelConfigs(config string) ([]AIModelConfig, error) {

pipeline := parts[0]
modelID := parts[1]
warm, err := strconv.ParseBool(parts[3])
warm, err := strconv.ParseBool(parts[2])
if err != nil {
return nil, err
}
Expand Down
84 changes: 84 additions & 0 deletions core/ai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package core
import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"sync"
"testing"
Expand Down Expand Up @@ -697,3 +699,85 @@ func (s *StubAIWorkerServer) Send(n *net.NotifyAIJob) error {
return nil

}

// Utility function to create a temporary file for file-based configurations
func mockFile(t *testing.T, content string) string {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "config.json")
err := os.WriteFile(filePath, []byte(content), 0644)
if err != nil {
t.Fatalf("Failed to write mock file: %v", err)
}
return filePath
}

func TestParseAIModelConfigs(t *testing.T) {
tests := []struct {
name string
input string
fileData string
expected []AIModelConfig
expectedErr string
}{{
name: "Valid Inline String Config",
input: "pipeline1:model1:true,pipeline2:model2:false",
expected: []AIModelConfig{
{Pipeline: "pipeline1", ModelID: "model1", Warm: true},
{Pipeline: "pipeline2", ModelID: "model2", Warm: false},
},
},
{
name: "Invalid Inline String Config Missing Parts",
input: "pipeline1:model1",
expectedErr: "invalid AI model config expected <pipeline>:<model_id>:<warm>",
},
{
name: "Valid File-Based Config",
fileData: `[{"pipeline": "pipeline1", "model_id": "model1", "warm": true}, {"pipeline": "pipeline2", "model_id": "model2", "warm": false}]`,
expected: []AIModelConfig{
{Pipeline: "pipeline1", ModelID: "model1", Warm: true},
{Pipeline: "pipeline2", ModelID: "model2", Warm: false},
},
},
{
name: "Invalid File Config Corrupted JSON",
fileData: `[{"pipeline": "pipeline1", "model_id": "model1", "warm": true`,
expectedErr: "unexpected end of JSON input",
},
{
name: "File Not Found",
input: "nonexistent.json",
expectedErr: "invalid AI model config expected <pipeline>:<model_id>:<warm>",
},
{
name: "Invalid Boolean Value in Inline String Config",
input: "pipeline1:model1:invalid_bool",
expectedErr: "strconv.ParseBool: parsing \"invalid_bool\": invalid syntax",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var result []AIModelConfig
var err error

// Mock file handling if fileData is provided
if tt.fileData != "" {
mockFilePath := mockFile(t, tt.fileData)
result, err = ParseAIModelConfigs(mockFilePath)
} else {
result, err = ParseAIModelConfigs(tt.input)
}

// Verify error messages match
assert := assert.New(t)
if tt.expectedErr != "" {
assert.Equal(err.Error(), tt.expectedErr)
assert.Empty(result, err)
} else {
assert.Empty(err)
assert.Equal(tt.expected, result)
}
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/livepeer/go-livepeer

go 1.21.5
go 1.23.2

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2
Expand Down

0 comments on commit 6f40b18

Please sign in to comment.