mirror of
https://github.com/kairos-io/immucore.git
synced 2025-08-18 06:07:11 +00:00
Timeout must be created before, not during consumption
Fix: https://github.com/kairos-io/immucore/issues/12
This commit is contained in:
parent
45e2622cd1
commit
70cce41004
@ -92,6 +92,7 @@ func (s *State) RunStageOp(stage string) func(context.Context) error {
|
|||||||
func (s *State) MountOP(what, where, t string, options []string, timeout time.Duration) func(context.Context) error {
|
func (s *State) MountOP(what, where, t string, options []string, timeout time.Duration) func(context.Context) error {
|
||||||
s.Logger.Debug().Str("what", what).Str("where", where).Str("type", t)
|
s.Logger.Debug().Str("what", what).Str("where", where).Str("type", t)
|
||||||
return func(c context.Context) error {
|
return func(c context.Context) error {
|
||||||
|
cc := time.After(timeout)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
default:
|
default:
|
||||||
@ -119,7 +120,7 @@ func (s *State) MountOP(what, where, t string, options []string, timeout time.Du
|
|||||||
return nil
|
return nil
|
||||||
case <-c.Done():
|
case <-c.Done():
|
||||||
return fmt.Errorf("context canceled")
|
return fmt.Errorf("context canceled")
|
||||||
case <-time.After(timeout):
|
case <-cc:
|
||||||
return fmt.Errorf("timeout exhausted")
|
return fmt.Errorf("timeout exhausted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package mount_test
|
package mount_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/kairos-io/immucore/pkg/mount"
|
"github.com/kairos-io/immucore/pkg/mount"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@ -97,5 +100,13 @@ var _ = Describe("mounting immutable setup", func() {
|
|||||||
Expect(dag[7][0].Name).To(Equal("mount-bind"))
|
Expect(dag[7][0].Name).To(Equal("mount-bind"))
|
||||||
Expect(dag[8][0].Name).To(Equal("write-fstab"))
|
Expect(dag[8][0].Name).To(Equal("write-fstab"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("Mountop timeouts", func() {
|
||||||
|
s := &mount.State{}
|
||||||
|
f := s.MountOP("", "", "", []string{}, 1*time.Second)
|
||||||
|
err := f(context.Background())
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(err.Error()).To(ContainSubstring("exhausted"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user