-
Notifications
You must be signed in to change notification settings - Fork 34
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
A simple long running test #598
base: main
Are you sure you want to change the base?
Changes from 4 commits
a0af203
f429274
06a69ca
0a73c1d
929f2f0
6297ac8
73d0d9b
4bdf9d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package longrunning | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/celestiaorg/knuu/pkg/instance" | ||
"github.com/celestiaorg/knuu/pkg/knuu" | ||
) | ||
|
||
const ( | ||
alpineImage = "alpine:3.20.3" | ||
testTimeout = time.Minute * 15 | ||
) | ||
|
||
func TestSimple(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test where we test to change something (for example, the image) of an already running instance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes will add it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it is added now. There was an issue with pvc applying and that one is also resolved in the recent commit |
||
const ( | ||
instanceName = "simple-id" | ||
fileContent = "identifier:12345" | ||
) | ||
|
||
ctx := context.Background() | ||
|
||
ins1, err := createInstance(ctx, instanceName, "") | ||
require.NoError(t, err) | ||
testScope := ins1.Scope | ||
|
||
t.Logf("Scope: %s", testScope) | ||
|
||
_, err = ins1.Execution().ExecuteCommand(ctx, "echo", fileContent, ">", "/tmp/test-id") | ||
require.NoError(t, err) | ||
|
||
time.Sleep(1 * time.Second) | ||
mojtaba-esk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ins2, err := createInstance(ctx, instanceName, testScope) | ||
require.NoError(t, err) | ||
|
||
out, err := ins2.Execution().ExecuteCommand(ctx, "cat", "/tmp/test-id") | ||
require.NoError(t, err) | ||
require.Contains(t, out, fileContent) | ||
} | ||
|
||
func createInstance(ctx context.Context, name, testScope string) (*instance.Instance, error) { | ||
knOpts := knuu.Options{Timeout: testTimeout} | ||
if testScope != "" { | ||
knOpts.Scope = testScope | ||
} | ||
|
||
kn, err := knuu.New(ctx, knOpts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
kn.HandleStopSignal(ctx) | ||
|
||
ins, err := kn.NewInstance(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := ins.Build().SetImage(ctx, alpineImage); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := ins.Build().Commit(ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := ins.Build().SetStartCommand("sleep", "infinity"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := ins.Execution().Start(ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
return ins, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking for this PR, but I'm curious.
How would it look if I wanted to delete an instance from a long-running test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genius question, I will think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe user can just use the
Destroy()
method and it should work.