// Run runs the Prove engine, performing all steps of the proof process.
772900
func (p *Prove) Run(m libkb.MetaContext) (err error) {
	defer m.Trace("ProofEngine.Run", func() error { return err })()

	stage := func(s string) {
		m.Debug("| ProofEngine.Run() %s", s)
	}

	stage("GetServiceType")
	if err = p.getServiceType(m); err != nil {
		return err
	}
	stage("LoadMe")
	if err = p.loadMe(m); err != nil {
		return err
	}
	stage("CheckExists1")
	if err = p.checkExists1(m); err != nil {
		return err
	}
	stage("PromptRemoteName")
	if err = p.promptRemoteName(m); err != nil {
		return err
	}
	stage("CheckExists2")
	if err = p.checkExists2(m); err != nil {
		return err
	}
	stage("DoPrechecks")
	if err = p.doPrechecks(m); err != nil {
		return err
	}
	stage("DoWarnings")
	if err = p.doWarnings(m); err != nil {
		return err
	}
	m.G().LocalSigchainGuard().Set(m.Ctx(), "Prove")
	defer m.G().LocalSigchainGuard().Clear(m.Ctx(), "Prove")
	stage("GenerateProof")
	if err = p.generateProof(m); err != nil {
		return err
	}
	stage("PostProofToServer")
	if err = p.postProofToServer(m); err != nil {
		return err
	}
	m.G().LocalSigchainGuard().Clear(m.Ctx(), "Prove")
	stage("CheckProofText")
	if err = p.checkProofText(m); err != nil {
		return err
	}
	stage("InstructAction")
	if err = p.instructAction(m); err != nil {
		return err
	}

	if !p.arg.PromptPosted {
		m.Debug("PromptPosted not set, prove run finished")
		return nil
	}

	stage("CheckStart")
	if p.serviceParameters == nil {
		stage("PromptPostedLoop")
		if err = p.promptPostedLoop(m); err != nil {
			return err
		}
	} else {
		stage("VerifyLoop")
		if err = p.verifyLoop(m); err != nil {
			return err
		}
	}
	m.UIs().LogUI.Notice("Success!")
	return nil
}
501432
func (o *TraceOptions) Run() error {
	g, err := o.GraphOptions.BuildGraph()
	if err != nil {
		return err
	}

	return o.outputGraph(g)
}
1083588
func (e *Executor) Run(ctx context.Context, command []string) error {
	// Clear any previous state.
	e.executed = false
	e.returnCode = 0
	e.step = nil

	if len(command) == 0 {
		return errors.New("no command")
	}

	ctx, cancelFunc := context.WithCancel(ctx)
	cmd := exec.CommandContext(ctx, command[0], command[1:]...)

	// STDOUT
	stdoutRC, err := cmd.StdoutPipe()
	if err != nil {
		return fmt.Errorf("failed to create STDOUT pipe: %s", err)
	}
	defer stdoutRC.Close()
	stdout := e.configStream(stdoutRC, annotee.STDOUT, e.TeeStdout, true)

	stderrRC, err := cmd.StderrPipe()
	if err != nil {
		return fmt.Errorf("failed to create STDERR pipe: %s", err)
	}
	defer stderrRC.Close()
	stderr := e.configStream(stderrRC, annotee.STDERR, e.TeeStderr, false)

	// Start our process.
	if err := cmd.Start(); err != nil {
		return fmt.Errorf("failed to start bootstrapped process: %s", err)
	}

	// Cleanup the process on exit, and record its status and return code.
	defer func() {
		if err := cmd.Wait(); err != nil {
			var ok bool
			if e.returnCode, ok = exitcode.Get(err); ok {
				e.executed = true
			} else {
				log.WithError(err).Errorf(ctx, "Failed to Wait() for bootstrapped process.")
			}
		} else {
			e.returnCode = 0
			e.executed = true
		}
	}()

	// Probe our execution information.
	options := e.Options
	if options.Execution == nil {
		options.Execution = annotation.ProbeExecution(command, nil, "")
	}

	// Configure our Processor.
	streams := []*annotee.Stream{
		stdout,
		stderr,
	}

	// Process the bootstrapped I/O. We explicitly defer a Finish here to ensure
	// that we clean up any internal streams if our Processor fails/panics.
	//
	// If we fail to process the I/O, terminate the bootstrapped process
	// immediately, since it may otherwise block forever on I/O.
	proc := annotee.New(ctx, options)
	defer proc.Finish()

	if err := proc.RunStreams(streams); err != nil {
		cancelFunc()
		return fmt.Errorf("failed to process bootstrapped I/O: %v", err)
	}

	// Finish and record our annotation steps on completion.
	if e.step, err = proto.Marshal(proc.Finish().RootStep().Proto()); err != nil {
		log.WithError(err).Errorf(ctx, "Failed to Marshal final Step protobuf on completion.")
		return err
	}
	return nil
}
189473
func (e *PaperKeyPrimary) Run(m libkb.MetaContext) error {
	var err error
	e.passphrase, err = libkb.MakePaperKeyPhrase(libkb.PaperKeyVersion)
	if err != nil {
		return err
	}

	kgarg := &PaperKeyGenArg{
		Passphrase:     e.passphrase,
		Me:             e.args.Me,
		SigningKey:     e.args.SigningKey,
		EncryptionKey:  e.args.EncryptionKey,
		PerUserKeyring: e.args.PerUserKeyring,
	}
	kgeng := NewPaperKeyGen(e.G(), kgarg)
	if err := RunEngine2(m, kgeng); err != nil {
		return err
	}

	// If they refuse to write down their key, don't kill the login flow, just print an
	// ugly warning, which likely they won't see...
	w := m.UIs().LoginUI.DisplayPrimaryPaperKey(m.Ctx(), keybase1.DisplayPrimaryPaperKeyArg{Phrase: e.passphrase.String()})
	if w != nil {
		m.G().Log.Errorf("Display paper key failure: %s", w.Error())
	}

	return nil
}
948623
func (x *executor) Run(op Operation) error {
	logger.Debugf("running operation %v", op)

	if op.NeedsGlobalMachineLock() {
		releaser, err := x.acquireMachineLock(op.String())
		if err != nil {
			return errors.Annotate(err, "could not acquire lock")
		}
		defer logger.Debugf("lock released")
		defer releaser()
	}

	switch err := x.do(op, stepPrepare); errors.Cause(err) {
	case ErrSkipExecute:
	case nil:
		if err := x.do(op, stepExecute); err != nil {
			return err
		}
	default:
		return err
	}
	return x.do(op, stepCommit)
}
791967
func (m *Main) Run() error {
	m.Logger.Info("running")

	// Read or generate the instance identifier from file.
	id, err := m.readID(filepath.Join(m.DataDir, "instance_id"))
	if err != nil {
		return err
	}
	m.Process.ID = id
	m.Process.DataDir = m.DataDir
	m.Process.Logger = m.Logger.New("component", "process", "id", id)

	// Start process.
	m.Logger.Info("starting process", "id", id)
	if err := m.Process.Start(); err != nil {
		m.Logger.Error("error starting process", "err", err)
		return err
	}

	// Add service to discoverd registry.
	m.Logger.Info("adding service", "name", m.ServiceName)
	if err = m.DiscoverdClient.AddService(m.ServiceName, nil); err != nil && !httphelper.IsObjectExistsError(err) {
		m.Logger.Error("error adding discoverd service", "err", err)
		return err
	}
	inst := &discoverd.Instance{
		Addr: ":" + m.Process.Port,
		Meta: map[string]string{"REDIS_ID": id},
	}

	// Register instance and retain heartbeater.
	m.Logger.Info("registering instance", "addr", inst.Addr, "meta", inst.Meta)
	hb, err := m.DiscoverdClient.RegisterInstance(m.ServiceName, inst)
	if err != nil {
		m.Logger.Error("error registering discoverd instance", "err", err)
		return err
	}
	m.hb = hb
	shutdown.BeforeExit(func() { hb.Close() })

	m.Logger.Info("opening port", "addr", m.Addr)

	// Open HTTP port.
	ln, err := net.Listen("tcp", m.Addr)
	if err != nil {
		m.Logger.Error("error opening port", "err", err)
		return err
	}
	m.ln = keepalive.Listener(ln)

	// Initialize and server handler.
	m.Logger.Info("serving http api")
	h := redis.NewHandler()
	h.Process = m.Process
	h.Heartbeater = m.hb
	h.Logger = m.Logger.New("component", "http")
	go func() { http.Serve(ln, h) }()

	return nil
}
1028518
func Run(cmd string, args ...string) error {
	return RunWith(nil, cmd, args...)
}
371626
func (e *Engine) Run() {
	log.Infof("Seesaw Engine starting for %s", e.config.ClusterName)

	e.initNetwork()

	n, err := config.NewNotifier(e.config)
	if err != nil {
		log.Fatalf("config.NewNotifier() failed: %v", err)
	}
	e.notifier = n

	if e.config.AnycastEnabled {
		go e.bgpManager.run()
	}
	go e.hcManager.run()

	go e.syncClient.run()
	go e.syncServer.run()

	go e.syncRPC()
	go e.engineIPC()
	go e.gratuitousARP()

	e.manager()
}
714807
func (rp *Reprovider) Run(proc goprocess.Process) {
	ctx := goprocessctx.WithProcessClosing(rp.ctx, proc)
	defer close(rp.closing)

	// dont reprovide immediately.
	// may have just started the daemon and shutting it down immediately.
	// probability( up another minute | uptime ) increases with uptime.
	after := time.After(time.Minute)
	var done doneFunc
	for {
		if rp.tick == 0 {
			after = make(chan time.Time)
		}

		select {
		case <-ctx.Done():
			return
		case done = <-rp.trigger:
		case <-after:
		}

		// 'mute' the trigger channel so when `ipfs bitswap reprovide` is called
		// a 'reprovider is already running' error is returned
		unmute := rp.muteTrigger()

		err := rp.reprovide(ctx)
		if err != nil {
			log.Debug(err)
		}

		if done != nil {
			done(err)
		}

		unmute()

		after = time.After(rp.tick)
	}
}
177635
func Run(t *testing.T, config *Config) {
	t.Run("PublishSubscribeQOS0", func(t *testing.T) {
		PublishSubscribeTest(t, config, "pubsub/1", "pubsub/1", 0, 0, 0)
	})

	t.Run("PublishSubscribeQOS1", func(t *testing.T) {
		PublishSubscribeTest(t, config, "pubsub/2", "pubsub/2", 1, 1, 1)
	})

	t.Run("PublishSubscribeQOS2", func(t *testing.T) {
		PublishSubscribeTest(t, config, "pubsub/3", "pubsub/3", 2, 2, 2)
	})

	t.Run("PublishSubscribeQOSKeep0", func(t *testing.T) {
		PublishSubscribeTest(t, config, "keep/1", "keep/1", 1, 0, 0)
	})

	t.Run("PublishSubscribeQOSKeep1", func(t *testing.T) {
		PublishSubscribeTest(t, config, "keep/2", "keep/2", 2, 1, 1)
	})

	t.Run("PublishSubscribeWildcardOne", func(t *testing.T) {
		PublishSubscribeTest(t, config, "wildcard/1/foo", "wildcard/1/+", 0, 0, 0)
	})

	t.Run("PublishSubscribeWildcardSome", func(t *testing.T) {
		PublishSubscribeTest(t, config, "wildcard/2/foo", "wildcard/2/#", 0, 0, 0)
	})

	t.Run("PublishSubscribeQOSDowngrade1To0", func(t *testing.T) {
		PublishSubscribeTest(t, config, "downgrade/1", "downgrade/1", 0, 1, 0)
	})

	t.Run("PublishSubscribeQOSDowngrade2To0", func(t *testing.T) {
		PublishSubscribeTest(t, config, "downgrade/2", "downgrade/2", 0, 2, 0)
	})

	t.Run("PublishSubscribeQOSDowngrade2To1", func(t *testing.T) {
		PublishSubscribeTest(t, config, "downgrade/3", "downgrade/3", 1, 2, 1)
	})

	t.Run("UnsubscribeQOS0", func(t *testing.T) {
		UnsubscribeTest(t, config, "unsub/1", 0)
	})

	t.Run("UnsubscribeQOS1", func(t *testing.T) {
		UnsubscribeTest(t, config, "unsub/2", 1)
	})

	t.Run("UnsubscribeQOS2", func(t *testing.T) {
		UnsubscribeTest(t, config, "unsub/3", 2)
	})

	t.Run("UnsubscribeNotExistingSubscription", func(t *testing.T) {
		UnsubscribeNotExistingSubscriptionTest(t, config, "unsub/4")
	})

	t.Run("UnsubscribeOverlappingSubscription", func(t *testing.T) {
		UnsubscribeOverlappingSubscriptions(t, config, "unsub/5")
	})

	t.Run("SubscriptionUpgradeQOS0To1", func(t *testing.T) {
		SubscriptionUpgradeTest(t, config, "subup/1", 0, 1)
	})

	t.Run("SubscriptionUpgradeQOS1To2", func(t *testing.T) {
		SubscriptionUpgradeTest(t, config, "subup/2", 1, 2)
	})

	t.Run("OverlappingSubscriptionsWildcardOne", func(t *testing.T) {
		OverlappingSubscriptionsTest(t, config, "ovlsub/1/foo", "ovlsub/1/+")
	})

	t.Run("OverlappingSubscriptionsWildcardSome", func(t *testing.T) {
		OverlappingSubscriptionsTest(t, config, "ovlsub/2/foo", "ovlsub/2/#")
	})

	t.Run("MultipleSubscription", func(t *testing.T) {
		MultipleSubscriptionTest(t, config, "mulsub")
	})

	t.Run("DuplicateSubscription", func(t *testing.T) {
		DuplicateSubscriptionTest(t, config, "dblsub")
	})

	t.Run("IsolatedSubscription", func(t *testing.T) {
		IsolatedSubscriptionTest(t, config, "islsub")
	})

	t.Run("WillQOS0", func(t *testing.T) {
		WillTest(t, config, "will/1", 0, 0)
	})

	t.Run("WillQOS1", func(t *testing.T) {
		WillTest(t, config, "will/2", 1, 1)
	})

	t.Run("WillQOS2", func(t *testing.T) {
		WillTest(t, config, "will/3", 2, 2)
	})

	t.Run("CleanWill", func(t *testing.T) {
		CleanWillTest(t, config, "will/4")
	})

	t.Run("KeepAlive", func(t *testing.T) {
		KeepAliveTest(t, config)
	})

	t.Run("KeepAliveTimeout", func(t *testing.T) {
		KeepAliveTimeoutTest(t, config)
	})

	t.Run("UnexpectedPubrel", func(t *testing.T) {
		UnexpectedPubrelTest(t, config)
	})

	if config.RetainedMessages {
		t.Run("RetainedMessageQOS0", func(t *testing.T) {
			RetainedMessageTest(t, config, "retained/1", "retained/1", 0, 0)
		})

		t.Run("RetainedMessageQOS1", func(t *testing.T) {
			RetainedMessageTest(t, config, "retained/2", "retained/2", 1, 1)
		})

		t.Run("RetainedMessageQOS2", func(t *testing.T) {
			RetainedMessageTest(t, config, "retained/3", "retained/3", 2, 2)
		})

		t.Run("RetainedMessageDowngrade1To0", func(t *testing.T) {
			RetainedMessageTest(t, config, "retained/4", "retained/4", 0, 1)
		})

		t.Run("RetainedMessageDowngrade2To0", func(t *testing.T) {
			RetainedMessageTest(t, config, "retained/5", "retained/5", 0, 2)
		})

		t.Run("RetainedMessageDowngrade2To1", func(t *testing.T) {
			RetainedMessageTest(t, config, "retained/6", "retained/6", 1, 2)
		})

		t.Run("RetainedMessageWildcardOne", func(t *testing.T) {
			RetainedMessageTest(t, config, "retained/7/foo/bar", "retained/7/foo/+", 0, 0)
		})

		t.Run("RetainedMessageWildcardSome", func(t *testing.T) {
			RetainedMessageTest(t, config, "retained/8/foo/bar", "retained/8/#", 0, 0)
		})

		t.Run("RetainedMessageReplace", func(t *testing.T) {
			RetainedMessageReplaceTest(t, config, "retained/9")
		})

		t.Run("ClearRetainedMessage", func(t *testing.T) {
			ClearRetainedMessageTest(t, config, "retained/10")
		})

		t.Run("DirectRetainedMessage", func(t *testing.T) {
			DirectRetainedMessageTest(t, config, "retained/11")
		})

		t.Run("DirectClearRetainedMessage", func(t *testing.T) {
			DirectClearRetainedMessageTest(t, config, "retained/12")
		})

		t.Run("RetainedWill", func(t *testing.T) {
			RetainedWillTest(t, config, "retained/13")
		})

		t.Run("RetainedMessageResubscription", func(t *testing.T) {
			RetainedMessageResubscriptionTest(t, config, "retained/14")
		})
	}

	if config.StoredPackets {
		t.Run("PublishResendQOS1", func(t *testing.T) {
			PublishResendQOS1Test(t, config, "pubres/1")
		})

		t.Run("PublishResendQOS2", func(t *testing.T) {
			PublishResendQOS2Test(t, config, "pubres/2")
		})

		t.Run("PubrelResendQOS2", func(t *testing.T) {
			PubrelResendQOS2Test(t, config, "pubres/3")
		})
	}

	if config.StoredSubscriptions {
		t.Run("StoredSubscriptionsQOS0", func(t *testing.T) {
			StoredSubscriptionsTest(t, config, "strdsub/1", 0)
		})

		t.Run("StoredSubscriptionsQOS1", func(t *testing.T) {
			StoredSubscriptionsTest(t, config, "strdsub/2", 1)
		})

		t.Run("StoredSubscriptionsQOS2", func(t *testing.T) {
			StoredSubscriptionsTest(t, config, "strdsub/3", 2)
		})

		t.Run("CleanStoredSubscriptions", func(t *testing.T) {
			CleanStoredSubscriptionsTest(t, config, "strdsub/4")
		})

		t.Run("RemoveStoredSubscription", func(t *testing.T) {
			RemoveStoredSubscriptionTest(t, config, "strdsub/5")
		})
	}

	if config.OfflineSubscriptions {
		t.Run("OfflineSubscriptionQOS00", func(t *testing.T) {
			OfflineSubscriptionTest(t, config, "offsub/1", 0, 0, false)
		})

		t.Run("OfflineSubscriptionQOS01", func(t *testing.T) {
			OfflineSubscriptionTest(t, config, "offsub/2", 0, 1, false)
		})

		t.Run("OfflineSubscriptionQOS10", func(t *testing.T) {
			OfflineSubscriptionTest(t, config, "offsub/3", 1, 0, false)
		})

		t.Run("OfflineSubscriptionQOS11", func(t *testing.T) {
			OfflineSubscriptionTest(t, config, "offsub/4", 1, 1, true)
		})

		t.Run("OfflineSubscriptionQOS12", func(t *testing.T) {
			OfflineSubscriptionTest(t, config, "offsub/5", 1, 2, true)
		})

		t.Run("OfflineSubscriptionQOS21", func(t *testing.T) {
			OfflineSubscriptionTest(t, config, "offsub/6", 2, 1, true)
		})

		t.Run("OfflineSubscriptionQOS22", func(t *testing.T) {
			OfflineSubscriptionTest(t, config, "offsub/7", 2, 2, true)
		})
	}

	if config.OfflineSubscriptions && config.RetainedMessages {
		t.Run("OfflineSubscriptionRetainedQOS0", func(t *testing.T) {
			OfflineSubscriptionRetainedTest(t, config, "offsubret/1", 0, 0, false)
		})

		t.Run("OfflineSubscriptionRetainedQOS1", func(t *testing.T) {
			OfflineSubscriptionRetainedTest(t, config, "offsubret/2", 1, 1, true)
		})

		t.Run("OfflineSubscriptionRetainedQOS2", func(t *testing.T) {
			OfflineSubscriptionRetainedTest(t, config, "offsubret/3", 2, 2, true)
		})
	}

	if config.Authentication {
		t.Run("Authentication", func(t *testing.T) {
			AuthenticationTest(t, config)
		})
	}

	if config.UniqueClientIDs {
		t.Run("UniqueClientIDUnclean", func(t *testing.T) {
			UniqueClientIDUncleanTest(t, config)
		})

		t.Run("UniqueClientIDClean", func(t *testing.T) {
			UniqueClientIDCleanTest(t, config)
		})
	}

	if config.RootSlashDistinction {
		t.Run("RootSlashDistinction", func(t *testing.T) {
			RootSlashDistinctionTest(t, config, "rootslash")
		})
	}
}
676375
func (e *DeviceKeygen) Run(m libkb.MetaContext) (err error) {
	defer m.Trace("DeviceKeygen#Run", func() error { return err })()

	e.setup(m)
	e.generate(m)
	e.localSave(m)
	return e.runErr
}
46883
func (darwin *darwinRecord) Run(e Executable) (string, error) {
	runAction := "Running " + darwin.description + ":"
	e.Run()
	return runAction + " completed.", nil
}
541375
func (c *slaCommand) Run(ctx *cmd.Context) error {
	root, err := c.newAPIRoot()
	if err != nil {
		return errors.Trace(err)
	}
	client := c.newSLAClient(root)
	modelId := modelId(root)
	modelNameMap := modelNameMap()
	modelName := modelId
	if name, ok := modelNameMap[modelId]; ok {
		modelName = name
	}

	if c.Level == "" {
		return c.displayCurrentLevel(client, modelName, ctx)
	}
	owner, message, credentials, err := c.requestSupportCredentials(modelId)
	if err != nil {
		return errors.Trace(err)
	}
	if message != "" {
		err = c.out.Write(ctx, &slaLevel{
			Model:   modelName,
			SLA:     c.Level,
			Message: message,
		})
		if err != nil {
			return errors.Trace(err)
		}
	}
	err = client.SetSLALevel(c.Level, owner, credentials)
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}
643613
func (f *CLI) Run() bool {
	err := f.validate()
	if err != nil {
		os.Stderr.WriteString(err.Error() + "\n")
		os.Exit(1)
	}

	switch {
	case f.install:
		f.prompt()
		err = install.Install(f.Name)
	case f.uninstall:
		f.prompt()
		err = install.Uninstall(f.Name)
	default:
		// non of the action flags matched,
		// returning false should make the real program execute
		return false
	}

	if err != nil {
		fmt.Printf("%s failed! %s\n", f.action(), err)
		os.Exit(3)
	}
	fmt.Println("Done!")
	return true
}
311388
func (r *runner) Run(ctx context.Context, args *pb.RunnerArgs) (*pb.Build, error) {
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()

	// Validate and normalize parameters.
	args = proto.Clone(args).(*pb.RunnerArgs)
	if err := normalizeArgs(args); err != nil {
		return nil, errors.Annotate(err, "invalid args").Err()
	}

	// Print our input.
	argsJSON, err := indentedJSONPB(args)
	if err != nil {
		return nil, err
	}
	logging.Infof(ctx, "RunnerArgs: %s", argsJSON)

	// Prepare workdir.
	if err := r.setupWorkDir(args.WorkDir); err != nil {
		return nil, err
	}

	// Prepare auth contexts.
	systemAuth, userAuth, err := setupAuth(ctx, args)
	if err != nil {
		return nil, err
	}
	defer systemAuth.Close()
	defer userAuth.Close()

	// Prepare a build listener.
	var listenerErr error
	var listenerErrMU sync.Mutex
	listener := newBuildListener(streamNamePrefix, func(err error) {
		logging.Errorf(ctx, "%s", err)

		listenerErrMU.Lock()
		defer listenerErrMU.Unlock()
		if listenerErr == nil {
			listenerErr = err
			logging.Warningf(ctx, "canceling the user subprocess")
			cancel()
		}
	})

	// Start a local LogDog server.
	logdogServ, err := r.startLogDog(ctx, args, systemAuth, listener)
	if err != nil {
		return nil, errors.Annotate(err, "failed to start local logdog server").Err()
	}
	defer func() {
		if logdogServ != nil {
			_ = logdogServ.Stop()
		}
	}()

	// Run the user executable.
	err = r.runUserExecutable(ctx, args, userAuth, logdogServ, streamNamePrefix)
	if err != nil {
		return nil, err
	}

	// Wait for logdog server to stop before returning the build.
	if err := logdogServ.Stop(); err != nil {
		return nil, errors.Annotate(err, "failed to stop logdog server").Err()
	}
	logdogServ = nil // do not stop for the second time.

	// Check listener error.
	listenerErrMU.Lock()
	err = listenerErr
	listenerErrMU.Unlock()
	if err != nil {
		return nil, err
	}

	// Read the final build state.
	build := listener.Build()
	if build == nil {
		return nil, errors.Reason("user executable did not send a build").Err()
	}

	// Print the final build state.
	buildJSON, err := indentedJSONPB(build)
	if err != nil {
		return build, err
	}
	logging.Infof(ctx, "final build state: %s", buildJSON)

	// TODO(nodir): make a final UpdateBuild call.

	return build, nil
}
318706
func (s *Simulation) Run(ctx context.Context, step *Step) (result *StepResult) {
	result = newStepResult()

	result.StartedAt = time.Now()
	defer func() { result.FinishedAt = time.Now() }()

	// watch network events for the duration of the step
	stop := s.watchNetwork(result)
	defer stop()

	// perform the action
	if err := step.Action(ctx); err != nil {
		result.Error = err
		return
	}

	// wait for all node expectations to either pass, error or timeout
	nodes := make(map[enode.ID]struct{}, len(step.Expect.Nodes))
	for _, id := range step.Expect.Nodes {
		nodes[id] = struct{}{}
	}
	for len(result.Passes) < len(nodes) {
		select {
		case id := <-step.Trigger:
			// skip if we aren't checking the node
			if _, ok := nodes[id]; !ok {
				continue
			}

			// skip if the node has already passed
			if _, ok := result.Passes[id]; ok {
				continue
			}

			// run the node expectation check
			pass, err := step.Expect.Check(ctx, id)
			if err != nil {
				result.Error = err
				return
			}
			if pass {
				result.Passes[id] = time.Now()
			}
		case <-ctx.Done():
			result.Error = ctx.Err()
			return
		}
	}

	return
}
926414
func (eng *Engine) Run() error {
	defer eng.free()
	eng.transport.Bind(eng.connection)
	eng.tick() // Start ticking if needed
	for eng.dispatch() {
		// Initiate read/write if needed
		eng.read()
		eng.write()
		select {
		case f := <-eng.inject: // User or IO action
			f()
		case <-eng.timer.C:
			eng.tick()
		}
	}
	eng.err.Set(EndpointError(eng.Connection()))
	eng.err.Set(eng.Transport().Condition().Error())
	close(eng.running)   // Signal goroutines have exited and Error is set, disable Inject()
	_ = eng.conn.Close() // Close conn, force read goroutine to exit (Inject will fail)
	return eng.err.Get()
}