Skip to content

Commit

Permalink
[tmpnet] Avoid calling Stat in advance of Read/Open (#3356)
Browse files Browse the repository at this point in the history
  • Loading branch information
marun authored Sep 4, 2024
1 parent ca0228a commit f733ece
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 3 additions & 5 deletions tests/fixture/tmpnet/node_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ func (p *NodeProcess) setProcessContext(processContext node.NodeProcessContext)

func (p *NodeProcess) readState() error {
path := p.getProcessContextPath()
if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {
bytes, err := os.ReadFile(path)
if errors.Is(err, fs.ErrNotExist) {
// The absence of the process context file indicates the node is not running
p.setProcessContext(node.NodeProcessContext{})
return nil
}

bytes, err := os.ReadFile(path)
if err != nil {
} else if err != nil {
return fmt.Errorf("failed to read node process context: %w", err)
}
processContext := node.NodeProcessContext{}
Expand Down
9 changes: 3 additions & 6 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package tmpnet
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -339,14 +340,10 @@ func WaitForActiveValidators(

// Reads subnets from [network dir]/subnets/[subnet name].json
func readSubnets(subnetDir string) ([]*Subnet, error) {
if _, err := os.Stat(subnetDir); os.IsNotExist(err) {
entries, err := os.ReadDir(subnetDir)
if errors.Is(err, os.ErrNotExist) {
return nil, nil
} else if err != nil {
return nil, err
}

entries, err := os.ReadDir(subnetDir)
if err != nil {
return nil, fmt.Errorf("failed to read subnet dir: %w", err)
}

Expand Down

0 comments on commit f733ece

Please sign in to comment.