Repository: threefoldtech/zos
Pull request #361 (2019-11-02 19:51:34)

Fix github actions workflow filesname
This changes small things on actions workflow:
- Revert coma on tf-autobuilder (not needed, let's keep dash like all other build)
- Fix the promote filename for development build

codecov[bot]: # [Codecov](https://codecov.io/gh/threefoldtech/zos/pull/361?src=pr&el=h1) Report
> Merging [#361](https://codecov.io/gh/threefoldtech/zos/pull/361?src=pr&el=desc) into [master](https://codecov.io/gh/threefoldtech/zos/commit/6c99336222aa9a8867ac227f0bacf184a5af9df1?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/threefoldtech/zos/pull/361/graphs/tree.svg?width=650&token=f7Vmq1OAEm&height=150&src=pr)](https://codecov.io/gh/threefoldtech/zos/pull/361?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #361   +/-   ##
=======================================
  Coverage   40.86%   40.86%           
=======================================
  Files          61       61           
  Lines        3783     3783           
=======================================
  Hits         1546     1546           
  Misses       2032     2032           
  Partials      205      205
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/threefoldtech/zos/pull/361?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/threefoldtech/zos/pull/361?src=pr&el=footer). Last update [6c99336...2d7b101](https://codecov.io/gh/threefoldtech/zos/pull/361?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.github/workflows/publish-development.yaml b/.github/workflows/publish-development.yaml
index 8ee64341..437a0877 100644
--- a/.github/workflows/publish-development.yaml
+++ b/.github/workflows/publish-development.yaml
@@ -40,12 +40,12 @@ jobs:
         user: tf-autobuilder
         root: archive
         token: ${{ secrets.HUB_JWT }}
-        name: zos:${{ github.sha }}.flist
+        name: zos-${{ github.sha }}.flist
 
     - name: Set name of the development build
       id: setname
       run: |
-        echo "::set-output name=build::zos-$(date +%y%m%d.%H%M%S.0)-dev.flist"
+        echo "::set-output name=build::zos:v$(date +%y%m%d.%H%M%S.0)-dev.flist"
 
     - name: Promote flist (${{ github.sha }})
       if: success()
@@ -55,7 +55,7 @@ jobs:
         user: tf-zos
         root: archive
         token: ${{ secrets.HUB_JWT }}
-        name: tf-autobuilder/zos:${{ github.sha }}.flist
+        name: tf-autobuilder/zos-${{ github.sha }}.flist
         target: ${{ steps.setname.outputs.build }}
 
     - name: Readlink of current development build
diff --git a/.github/workflows/publish-pre-release.yaml b/.github/workflows/publish-pre-release.yaml
index 5ce03a21..a43caf7a 100644
--- a/.github/workflows/publish-pre-release.yaml
+++ b/.github/workflows/publish-pre-release.yaml
@@ -49,7 +49,7 @@ jobs:
         user: tf-autobuilder
         root: archive
         token: ${{ secrets.HUB_JWT }}
-        name: zos:${{ github.sha }}.flist
+        name: zos-${{ github.sha }}.flist
 
     - name: Promote flist (${{ github.ref }})
       if: success()
@@ -58,7 +58,7 @@ jobs:
         action: promote
         user: tf-zos
         token: ${{ secrets.HUB_JWT }}
-        name: tf-autobuilder/zos:${{ github.sha }}.flist
+        name: tf-autobuilder/zos-${{ github.sha }}.flist
         target: zos:${{ github.ref }}.flist
 
     - name: Symlink flist (development)
diff --git a/.github/workflows/publish-release.yaml b/.github/workflows/publish-release.yaml
index e370ca9f..4338df2c 100644
--- a/.github/workflows/publish-release.yaml
+++ b/.github/workflows/publish-release.yaml
@@ -50,7 +50,7 @@ jobs:
         user: tf-autobuilder
         root: archive
         token: ${{ secrets.HUB_JWT }}
-        name: zos:${{ github.sha }}.flist
+        name: zos-${{ github.sha }}.flist
 
     - name: Promote flist (${{ github.ref }})
       if: success()
@@ -59,8 +59,8 @@ jobs:
         action: promote
         user: tf-zos
         token: ${{ secrets.HUB_JWT }}
-        name: tf-autobuilder/zos:${{ github.sha }}.flist
-        target: zos-${{ github.ref }}.flist
+        name: tf-autobuilder/zos-${{ github.sha }}.flist
+        target: zos:${{ github.ref }}.flist
     
     - name: Symlink flist (development)
       if: success()
diff --git a/pkg/provision/source.go b/pkg/provision/source.go
index 0f1ba5e1..167829a5 100644
--- a/pkg/provision/source.go
+++ b/pkg/provision/source.go
@@ -56,11 +56,10 @@ func (s *pollSource) Reservations(ctx context.Context) <-chan *Reservation {
 	go func() {
 		defer close(ch)
 		var from uint64
-		last := time.Now()
+		on := time.Now()
 		for {
-			now := time.Now()
-			time.Sleep(last.Sub(now))
-			last = now.Add(s.maxSleep)
+			time.Sleep(time.Until(on))
+			on = time.Now().Add(s.maxSleep)
 
 			res, err := s.store.Poll(pkg.StrIdentifier(s.nodeID), from)
 			if err != nil && err != ErrPollEOS {


Test patch:
diff --git a/pkg/provision/source_test.go b/pkg/provision/source_test.go
index 76e42585..a0473046 100644
--- a/pkg/provision/source_test.go
+++ b/pkg/provision/source_test.go
@@ -2,6 +2,7 @@ package provision
 
 import (
 	"context"
+	"fmt"
 	"testing"
 	"time"
 
@@ -78,3 +79,58 @@ func TestHTTPReservationSourceMultiple(t *testing.T) {
 	require.Equal("3-1", reservations[2].ID)
 	require.Equal("4-1", reservations[3].ID)
 }
+
+type TestTrackSource struct {
+	Max   uint64
+	ID    uint64
+	Calls []int64
+}
+
+func (s *TestTrackSource) Poll(nodeID pkg.Identifier, from uint64) ([]*Reservation, error) {
+	if s.ID == s.Max {
+		return nil, ErrPollEOS
+	}
+
+	s.Calls = append(s.Calls, time.Now().Unix())
+
+	defer func() {
+		s.ID++
+	}()
+
+	return []*Reservation{
+		&Reservation{
+			ID: fmt.Sprint(s.ID, "-", "0"),
+		},
+	}, nil
+}
+
+func TestHTTPReservationSourceSleep(t *testing.T) {
+	require := require.New(t)
+	store := TestTrackSource{
+		Max: 4,
+	}
+
+	nodeID := pkg.StrIdentifier("node-id")
+	source := PollSource(&store, nodeID)
+
+	// don't delay the test for long
+	source.(*pollSource).maxSleep = 3 * time.Second
+
+	chn := source.Reservations(context.Background())
+
+	reservations := []*Reservation{}
+	for res := range chn {
+		reservations = append(reservations, res)
+	}
+
+	require.Len(reservations, 4)
+	require.Equal("0-0", reservations[0].ID)
+	require.Equal("1-0", reservations[1].ID)
+	require.Equal("2-0", reservations[2].ID)
+	require.Equal("3-0", reservations[3].ID)
+
+	require.Len(store.Calls, 4)
+	for i := 1; i < len(store.Calls); i++ {
+		require.Equal(int64(3), store.Calls[i]-store.Calls[i-1])
+	}
+}