Skip to content
This repository has been archived by the owner on Feb 3, 2018. It is now read-only.

Refactor sourceMgr #196

Merged
merged 43 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
435120b
Initial sketch of new approach to sm concurrency
sdboyer Mar 16, 2017
83499b9
Add callManager
sdboyer Mar 20, 2017
ac0a291
Reorganize new components, add them to sourceMgr
sdboyer Mar 20, 2017
a72135d
Fixups in response to review
sdboyer Mar 22, 2017
fb146b4
Abstract out singleSourceCache concept
sdboyer Mar 22, 2017
7262376
Modify monitoredCmd to take a Context
sdboyer Mar 22, 2017
b55d922
Convert source, maybeSource to new cache system
sdboyer Mar 22, 2017
fc4c538
Make glide happy
sdboyer Mar 22, 2017
ff7e046
Flesh out sourceGateway to reasonably complete
sdboyer Mar 28, 2017
5f4c226
Convert sourceMgr calls to new systems
sdboyer Mar 28, 2017
7ec3c9c
Remove dead code, refactor tests so it compiles
sdboyer Mar 28, 2017
070cc51
Move deducers.go contents into existing files
sdboyer Mar 28, 2017
91fc75a
Pass more contexts, handle scheme mismatch case
sdboyer Mar 28, 2017
7e8801c
Update two old tightly coupled tests
sdboyer Mar 28, 2017
29dcabd
Fix dangling var
sdboyer Mar 28, 2017
13bc00d
Convert maybeSources to use new patterns
sdboyer Mar 29, 2017
96bd8df
Move source gateway setup into method, per review
sdboyer Mar 29, 2017
de3035d
Refactor more logic into gateway and out of src
sdboyer Mar 29, 2017
faedb0a
Circle wasn't failing on error
sdboyer Mar 30, 2017
e6ca116
Replace deduceCoord's action chan with a mutex
sdboyer Mar 30, 2017
1e7cb71
Pull out more cruft from sources
sdboyer Mar 30, 2017
dd1cc7a
Cut test time down significantly w/parallelism
sdboyer Mar 30, 2017
4a49499
Convert source methods to take only Revisions
sdboyer Mar 30, 2017
c26166d
Remove storeVersionMap() calls from source
sdboyer Mar 30, 2017
1c94d43
Make projectInfo entirely internal to source cache
sdboyer Mar 30, 2017
77721f3
Integrate context for essential vcs cmds
sdboyer Mar 30, 2017
0e6a532
Wrap all sourceGateway inner calls w/callMgr
sdboyer Mar 31, 2017
ace80fb
s/callManager/supervisor/g
sdboyer Mar 31, 2017
69d5059
Connect supervisor to top-level Release() logic
sdboyer Mar 31, 2017
89566ce
Re-enable multi fetch test
sdboyer Mar 31, 2017
2bbb626
Merge branch 'master' into sm-channels
sdboyer Mar 31, 2017
adc5291
Implement updateVersion() locally, with context
sdboyer Mar 31, 2017
5a6e64c
Condense the guts of source impl a bit more
sdboyer Apr 1, 2017
38bedf4
Make ProjectAnalyzer a solver param, not the sm
sdboyer Apr 1, 2017
4a9a453
More source-related cleanup and cruft removal.
sdboyer Apr 1, 2017
ef6e6d3
Update example with new ProjectAnalyzer pattern
sdboyer Apr 1, 2017
564fe67
Add sourceGateway tests
sdboyer Apr 3, 2017
2c2f561
chan instead of real sigs in TestSignalHandling
sdboyer Apr 3, 2017
a3c79f3
Go 1.7 compat: drop sort.Slice() usage
sdboyer Apr 3, 2017
8f20ffd
Trim unneccessary bits out of repo handling
sdboyer Apr 3, 2017
0eddf21
Rename update() to fetch() in local repo interface
sdboyer Apr 3, 2017
d59d8a6
Merge branch 'master' into sm-channels
sdboyer Apr 3, 2017
01e3ba5
Test more probative URL in TestUnreachableSource
sdboyer Apr 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,17 @@ var mkBridge = func(s *solver, sm SourceManager, down bool) sourceBridge {
}
}

func (b *bridge) GetManifestAndLock(id ProjectIdentifier, v Version) (Manifest, Lock, error) {
func (b *bridge) GetManifestAndLock(id ProjectIdentifier, v Version, an ProjectAnalyzer) (Manifest, Lock, error) {
if b.s.rd.isRoot(id.ProjectRoot) {
return b.s.rd.rm, b.s.rd.rl, nil
}

b.s.mtr.push("b-gmal")
m, l, e := b.sm.GetManifestAndLock(id, v)
m, l, e := b.sm.GetManifestAndLock(id, v, an)
b.s.mtr.pop()
return m, l, e
}

func (b *bridge) AnalyzerInfo() (string, int) {
return b.sm.AnalyzerInfo()
}

func (b *bridge) ListVersions(id ProjectIdentifier) ([]Version, error) {
if vl, exists := b.vlists[id]; exists {
return vl, nil
Expand Down
45 changes: 30 additions & 15 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gps

import (
"bytes"
"context"
"fmt"
"os/exec"
"sync"
Expand All @@ -11,27 +12,36 @@ import (
)

// monitoredCmd wraps a cmd and will keep monitoring the process until it
// finishes or a certain amount of time has passed and the command showed
// no signs of activity.
// finishes, the provided context is canceled, or a certain amount of time has
// passed and the command showed no signs of activity.
type monitoredCmd struct {
cmd *exec.Cmd
timeout time.Duration
ctx context.Context
stdout *activityBuffer
stderr *activityBuffer
}

func newMonitoredCmd(cmd *exec.Cmd, timeout time.Duration) *monitoredCmd {
stdout := newActivityBuffer()
stderr := newActivityBuffer()
cmd.Stderr = stderr
cmd.Stdout = stdout
return &monitoredCmd{cmd, timeout, stdout, stderr}
stdout, stderr := newActivityBuffer(), newActivityBuffer()
cmd.Stdout, cmd.Stderr = stdout, stderr
return &monitoredCmd{
cmd: cmd,
timeout: timeout,
stdout: stdout,
stderr: stderr,
}
}

// run will wait for the command to finish and return the error, if any. If the
// command does not show any activity for more than the specified timeout the
// process will be killed.
func (c *monitoredCmd) run() error {
func (c *monitoredCmd) run(ctx context.Context) error {
// Check for cancellation before even starting
if ctx.Err() != nil {
return ctx.Err()
}

ticker := time.NewTicker(c.timeout)
done := make(chan error, 1)
defer ticker.Stop()
Expand All @@ -52,6 +62,11 @@ func (c *monitoredCmd) run() error {

return &timeoutError{c.timeout}
}
case <-ctx.Done():
if err := c.cmd.Process.Kill(); err != nil {
return &killCmdError{err}
}
return c.ctx.Err()
case err := <-done:
return err
}
Expand All @@ -64,8 +79,8 @@ func (c *monitoredCmd) hasTimedOut() bool {
c.stdout.lastActivity().Before(t)
}

func (c *monitoredCmd) combinedOutput() ([]byte, error) {
if err := c.run(); err != nil {
func (c *monitoredCmd) combinedOutput(ctx context.Context) ([]byte, error) {
if err := c.run(ctx); err != nil {
return c.stderr.buf.Bytes(), err
}

Expand Down Expand Up @@ -112,15 +127,15 @@ type killCmdError struct {
}

func (e killCmdError) Error() string {
return fmt.Sprintf("error killing command after timeout: %s", e.err)
return fmt.Sprintf("error killing command: %s", e.err)
}

func runFromCwd(cmd string, args ...string) ([]byte, error) {
func runFromCwd(ctx context.Context, cmd string, args ...string) ([]byte, error) {
c := newMonitoredCmd(exec.Command(cmd, args...), 2*time.Minute)
return c.combinedOutput()
return c.combinedOutput(ctx)
}

func runFromRepoDir(repo vcs.Repo, cmd string, args ...string) ([]byte, error) {
func runFromRepoDir(ctx context.Context, repo vcs.Repo, cmd string, args ...string) ([]byte, error) {
c := newMonitoredCmd(repo.CmdFromDir(cmd, args...), 2*time.Minute)
return c.combinedOutput()
return c.combinedOutput(ctx)
}
10 changes: 8 additions & 2 deletions cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gps

import (
"context"
"fmt"
"os"
"os/exec"
Expand All @@ -16,14 +17,19 @@ func mkTestCmd(iterations int) *monitoredCmd {
}

func TestMonitoredCmd(t *testing.T) {
// Sleeps make this a bit slow
if testing.Short() {
t.Skip("skipping test with sleeps on short")
}

err := exec.Command("go", "build", "./_testdata/cmd/echosleep.go").Run()
if err != nil {
t.Errorf("Unable to build echosleep binary: %s", err)
}
defer os.Remove("./echosleep")

cmd := mkTestCmd(2)
err = cmd.run()
err = cmd.run(context.Background())
if err != nil {
t.Errorf("Expected command not to fail: %s", err)
}
Expand All @@ -34,7 +40,7 @@ func TestMonitoredCmd(t *testing.T) {
}

cmd2 := mkTestCmd(10)
err = cmd2.run()
err = cmd2.run(context.Background())
if err == nil {
t.Error("Expected command to fail")
}
Expand Down
Loading