Skip to content

Commit

Permalink
Add auto progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
q-uint committed Apr 24, 2024
1 parent 9897dd5 commit 013b03e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
10 changes: 10 additions & 0 deletions pocketic/pocketic.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ func (pic PocketIC) CanisterExits(canisterID principal.Principal) bool {
return err == nil
}

// AutoProgress enables auto progress for the PocketIC instance.
func (pic PocketIC) AutoProgress() error {
return pic.server.InstancePost(pic.instanceID, "auto_progress", nil, nil)
}

// StopProgress disables auto progress for the PocketIC instance.
func (pic PocketIC) StopProgress() error {
return pic.server.InstancePost(pic.instanceID, "stop_progress", nil, nil)
}

func (pic PocketIC) CreateAndInstallCanister(wasmModule io.Reader, arg []byte, subnetPID *principal.Principal) (*principal.Principal, error) {
canisterID, err := pic.CreateCanister(CreateCanisterArgs{}, subnetPID)
if err != nil {
Expand Down
15 changes: 12 additions & 3 deletions pocketic/pocketic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ func TestPocketIC(t *testing.T) {
dfxCacheCmd := exec.Command(dfxPath, "cache", "show")
dfxCacheCmd.Stdout = &out
if err := dfxCacheCmd.Run(); err != nil {
t.Skip(err)
t.Fatal(err)
}
mocPath := fmt.Sprintf("%s/moc", strings.TrimSpace(out.String()))
mocCmd := exec.Command(mocPath, "testdata/main.mo", "-o", "testdata/main.wasm", "--idl")
if err := mocCmd.Run(); err != nil {
t.Skip(err)
t.Fatal(err)
}
helloWasm, err := os.Open("testdata/main.wasm")
if err != nil {
t.Skip(err)
t.Fatal(err)
}
canisterID, err := s.CreateAndInstallCanister(helloWasm, nil, nil)
if err != nil {
Expand Down Expand Up @@ -83,6 +83,15 @@ func TestPocketIC(t *testing.T) {
t.Run("Agent UpdateCall", func(t *testing.T) {
t.Skip("PocketIC does not advance automatically, so the time is not updated.")

if err := s.AutoProgress(); err != nil {
t.Fatal(err)
}
defer func() {
if err := s.StopProgress(); err != nil {
t.Fatal(err)
}
}()

resp, err := a.HelloUpdate("there")
if err != nil {
t.Fatal(err)
Expand Down
18 changes: 10 additions & 8 deletions pocketic/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ type server struct {
func newServer() (*server, error) {
// Try to find the pocket-ic binary.
path, err := exec.LookPath("pocket-ic-server")
if path, err = exec.LookPath("pocket-ic"); err != nil {
// If the binary is not found, try to find it in the POCKET_IC_BIN environment variable.
if pathEnv := os.Getenv("POCKET_IC_BIN"); pathEnv != "" {
path = pathEnv
} else {
path = "./pocket-ic"
if _, err := os.Stat(path); err != nil {
return nil, fmt.Errorf("pocket-ic binary not found: %v", err)
if err != nil {
if path, err = exec.LookPath("pocket-ic"); err != nil {
// If the binary is not found, try to find it in the POCKET_IC_BIN environment variable.
if pathEnv := os.Getenv("POCKET_IC_BIN"); pathEnv != "" {
path = pathEnv
} else {
path = "./pocket-ic"
if _, err := os.Stat(path); err != nil {
return nil, fmt.Errorf("pocket-ic binary not found: %v", err)
}
}
}
}
Expand Down

0 comments on commit 013b03e

Please sign in to comment.