Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
4fec5816
Commit
4fec5816
authored
Mar 27, 2024
by
Daniel Hiltgen
Browse files
Integration test improvements
Cleaner shutdown logic, a bit of response hardening
parent
0a0e9f3e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
19 deletions
+34
-19
integration/basic_test.go
integration/basic_test.go
+1
-1
integration/utils_test.go
integration/utils_test.go
+33
-18
No files found.
integration/basic_test.go
View file @
4fec5816
...
@@ -24,5 +24,5 @@ func TestOrcaMiniBlueSky(t *testing.T) {
...
@@ -24,5 +24,5 @@ func TestOrcaMiniBlueSky(t *testing.T) {
"seed"
:
123
,
"seed"
:
123
,
},
},
}
}
GenerateTestHelper
(
ctx
,
t
,
&
http
.
Client
{},
req
,
[]
string
{
"rayleigh"
})
GenerateTestHelper
(
ctx
,
t
,
&
http
.
Client
{},
req
,
[]
string
{
"rayleigh"
,
"scattering"
})
}
}
integration/utils_test.go
View file @
4fec5816
...
@@ -126,7 +126,7 @@ func StartServer(ctx context.Context, ollamaHost string) error {
...
@@ -126,7 +126,7 @@ func StartServer(ctx context.Context, ollamaHost string) error {
}
}
func
PullIfMissing
(
ctx
context
.
Context
,
client
*
http
.
Client
,
scheme
,
testEndpoint
,
modelName
string
)
error
{
func
PullIfMissing
(
ctx
context
.
Context
,
client
*
http
.
Client
,
scheme
,
testEndpoint
,
modelName
string
)
error
{
slog
.
Debug
(
"checking status of model"
,
"model"
,
modelName
)
slog
.
Info
(
"checking status of model"
,
"model"
,
modelName
)
showReq
:=
&
api
.
ShowRequest
{
Name
:
modelName
}
showReq
:=
&
api
.
ShowRequest
{
Name
:
modelName
}
requestJSON
,
err
:=
json
.
Marshal
(
showReq
)
requestJSON
,
err
:=
json
.
Marshal
(
showReq
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -174,14 +174,21 @@ func PullIfMissing(ctx context.Context, client *http.Client, scheme, testEndpoin
...
@@ -174,14 +174,21 @@ func PullIfMissing(ctx context.Context, client *http.Client, scheme, testEndpoin
return
nil
return
nil
}
}
var
serverProcMutex
sync
.
Mutex
func
GenerateTestHelper
(
ctx
context
.
Context
,
t
*
testing
.
T
,
client
*
http
.
Client
,
genReq
api
.
GenerateRequest
,
anyResp
[]
string
)
{
func
GenerateTestHelper
(
ctx
context
.
Context
,
t
*
testing
.
T
,
client
*
http
.
Client
,
genReq
api
.
GenerateRequest
,
anyResp
[]
string
)
{
// TODO maybe stuff in an init routine?
lifecycle
.
InitLogging
()
requestJSON
,
err
:=
json
.
Marshal
(
genReq
)
requestJSON
,
err
:=
json
.
Marshal
(
genReq
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Error serializing request: %v"
,
err
)
t
.
Fatalf
(
"Error serializing request: %v"
,
err
)
}
}
defer
func
()
{
defer
func
()
{
if
t
.
Failed
()
&&
os
.
Getenv
(
"OLLAMA_TEST_EXISTING"
)
==
""
{
if
os
.
Getenv
(
"OLLAMA_TEST_EXISTING"
)
==
""
{
// TODO
defer
serverProcMutex
.
Unlock
()
if
t
.
Failed
()
{
fp
,
err
:=
os
.
Open
(
lifecycle
.
ServerLogFile
)
fp
,
err
:=
os
.
Open
(
lifecycle
.
ServerLogFile
)
if
err
!=
nil
{
if
err
!=
nil
{
slog
.
Error
(
"failed to open server log"
,
"logfile"
,
lifecycle
.
ServerLogFile
,
"error"
,
err
)
slog
.
Error
(
"failed to open server log"
,
"logfile"
,
lifecycle
.
ServerLogFile
,
"error"
,
err
)
...
@@ -200,10 +207,18 @@ func GenerateTestHelper(ctx context.Context, t *testing.T, client *http.Client,
...
@@ -200,10 +207,18 @@ func GenerateTestHelper(ctx context.Context, t *testing.T, client *http.Client,
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
slog
.
Warn
(
"failed to cleanup"
,
"logfile"
,
lifecycle
.
ServerLogFile
,
"error"
,
err
)
slog
.
Warn
(
"failed to cleanup"
,
"logfile"
,
lifecycle
.
ServerLogFile
,
"error"
,
err
)
}
}
}
}()
}()
scheme
,
testEndpoint
:=
GetTestEndpoint
()
scheme
,
testEndpoint
:=
GetTestEndpoint
()
if
os
.
Getenv
(
"OLLAMA_TEST_EXISTING"
)
==
""
{
if
os
.
Getenv
(
"OLLAMA_TEST_EXISTING"
)
==
""
{
serverProcMutex
.
Lock
()
fp
,
err
:=
os
.
CreateTemp
(
""
,
"ollama-server-*.log"
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate log file: %s"
,
err
)
}
lifecycle
.
ServerLogFile
=
fp
.
Name
()
fp
.
Close
()
assert
.
NoError
(
t
,
StartServer
(
ctx
,
testEndpoint
))
assert
.
NoError
(
t
,
StartServer
(
ctx
,
testEndpoint
))
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment