Skip to content

Commit

Permalink
Merge pull request #317 from spacemeshos/315-run-unit-tests-on-arm64-…
Browse files Browse the repository at this point in the history
…runners

Run unit tests on arm64 runners
  • Loading branch information
fasmat authored Jul 4, 2023
2 parents 573f98b + bb6e3e3 commit e33dd6b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os:
- ubuntu-latest
- [self-hosted, linux, arm64]
- macos-latest
- [self-hosted, macos, arm64]
- windows-latest
steps:
- name: checkout
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,6 @@ func (s *Service) loop(ctx context.Context, roundToResume *round) error {

for {
select {
case cmd := <-s.commands:
cmd(s)

case result := <-roundResults:
if result.err == nil {
s.onNewProof(result.round.ID, result.round.execution)
Expand All @@ -248,6 +245,9 @@ func (s *Service) loop(ctx context.Context, roundToResume *round) error {
})
s.executingRoundId = nil

case cmd := <-s.commands:
cmd(s)

case <-s.timer:
round := s.openRound
newRound, err := s.newRound(ctx, round.Epoch()+1)
Expand Down
55 changes: 28 additions & 27 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,36 @@ type challenge struct {

func TestService_Recovery(t *testing.T) {
req := require.New(t)
tempdir := t.TempDir()
genesis := time.Now().Add(2 * time.Second)
cfg := &service.Config{
Genesis: service.Genesis(time.Now().Add(time.Second)),
EpochDuration: time.Second * 5,
PhaseShift: time.Second * 2,
Genesis: service.Genesis(genesis),
EpochDuration: time.Second * 2,
PhaseShift: time.Second,
MaxRoundMembers: 100,
}
tempdir := t.TempDir()
start := make(chan struct{})
var tick *time.Ticker
time.AfterFunc(time.Until(genesis), func() {
tick = time.NewTicker(cfg.EpochDuration)
close(start)
})

// Generate groups of random challenges.
challengeGroupSize := byte(5)
challengeGroupSize := 5
challengeGroups := make([][]challenge, 3)
for g := byte(0); g < 3; g++ {
for g := 0; g < 3; g++ {
challengeGroup := make([]challenge, challengeGroupSize)
for i := byte(0); i < challengeGroupSize; i++ {
for i := 0; i < challengeGroupSize; i++ {
challengeGroup[i] = challenge{
data: bytes.Repeat([]byte{g*10 + i}, 32),
nodeID: bytes.Repeat([]byte{-g*10 - i}, 32),
data: bytes.Repeat([]byte{byte(g*10 + i)}, 32),
nodeID: bytes.Repeat([]byte{byte(-g*10 - i)}, 32),
}
}
challengeGroups[g] = challengeGroup
}

// Create a new service instance.
s, err := service.NewService(context.Background(), cfg, tempdir)
req.NoError(err)

submitChallenges := func(roundID string, challenges []challenge) {
submitChallenges := func(s *service.Service, roundID string, challenges []challenge) {
params := s.PowParams()
for _, challenge := range challenges {
nonce, _ := shared.FindSubmitPowNonce(
Expand All @@ -86,24 +89,25 @@ func TestService_Recovery(t *testing.T) {
}
}

// Create a new service instance.
s, err := service.NewService(context.Background(), cfg, tempdir)
req.NoError(err)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var eg errgroup.Group
eg.Go(func() error { return s.Run(ctx) })
req.NoError(s.Start(context.Background()))

// Submit challenges to open round (0).
submitChallenges("0", challengeGroups[0])
submitChallenges(s, "0", challengeGroups[0])

// Wait for round 0 to start executing.
req.Eventually(func() bool {
info, err := s.Info(context.Background())
req.NoError(err)
return info.ExecutingRoundId != nil && *info.ExecutingRoundId == "0"
}, cfg.EpochDuration*2, time.Millisecond*100)
<-start
<-tick.C

// Submit challenges to open round (1).
submitChallenges("1", challengeGroups[1])
submitChallenges(s, "1", challengeGroups[1])

cancel()
req.NoError(eg.Wait())
Expand All @@ -124,14 +128,11 @@ func TestService_Recovery(t *testing.T) {
req.Equal("0", *info.ExecutingRoundId)

req.NoError(s.Start(context.Background()))

// Wait for round 2 to open
req.Eventually(func() bool {
info, err := s.Info(context.Background())
req.NoError(err)
return info.OpenRoundID == "2"
}, cfg.EpochDuration*2, time.Millisecond*100)
<-tick.C

submitChallenges("2", challengeGroups[2])
submitChallenges(s, "2", challengeGroups[2])

for i := 0; i < len(challengeGroups); i++ {
proofMsg := <-s.ProofsChan()
Expand Down

0 comments on commit e33dd6b

Please sign in to comment.