Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jail.RemoveCells before logout and switching account #382

Merged
merged 16 commits into from Oct 16, 2017

Conversation

oleg-raev
Copy link
Contributor

Added methods:

  • Jail.RemoveCells
  • JailCell.Stop
  • Loop.Stop

Added call of method RemoveCells at begin of Logout action and begin of SelectAccount action of geth API

Added tests:

  • (api_test.go) TestJailRemoveCells
  • (api_test.go) TestLogoutRemovesCells
  • (jail_test.go) TestJailRemoveCells
  • (jail_cell_test.go) TestJailCellStopSetIntervalBeforeStop
  • (jail_cell_test.go) TestJailCellStopSetIntervalAfterStop
  • (jail_cell_test.go) TestJailCellStopTwice

Issue #260 - setInterval keeps on posting updates after the account has been switched

… call of method RemoveCells at begin of Logout action and begin of SelectAccount action of geth API
@oleg-raev oleg-raev changed the title Added method Jail.RemoveCells, method JailCell.Stop, Loop.Stop. Added… Jail.RemoveCells before logout and switching account Oct 5, 2017
@divan
Copy link
Contributor

divan commented Oct 5, 2017

@oleg-raev thanks for terrific work. This code is not easy to grasp quickly.
However, this functionality already has been implemented in https://github.com/status-im/status-go/pull/376/commits, and we're going to merge it today. The approach there is similar to yours, but uses context package for cancelling cells. Also that PR doesn't touch API part for now. What I really like is a test/code ratio, and I'd definitely revisit it after merging (we going to merge a bunch of pending refactoring branches).

For now, marking this as blocked by #376

@divan divan added the blocked label Oct 5, 2017
@oleg-raev
Copy link
Contributor Author

oleg-raev commented Oct 7, 2017

@divan Thank you for your update and quick merging your PR.

The approach there is similar to yours, but uses context package for cancelling cells

Yes, it looks better and easier.

I should resolve conflicts and update the pull request, right?
What about failing check? Is it a big problem?

@divan
Copy link
Contributor

divan commented Oct 7, 2017

I should resolve conflicts and update the pull request, right?

Umm, not yet, the changes were huge (including file renames). We're about to merge another PR, related to tests. Once it's done, we'll revisit this PR and probably will manually cherry pick some changes (like logout API, and especially tests).

@tiabc
Copy link
Contributor

tiabc commented Oct 9, 2017

Thank you very much for the contribution, @oleg-raev!

We may either cherry-pick needed commits from your branch manually, or you can groom this branch yourself after #375 is merged if you have time. Which one is preferred for you?

Added a zenhub dependency on #371 as per @divan's comment.
Also removing the blocked label as blocking state is seen from zenhub.

@oleg-raev
Copy link
Contributor Author

oleg-raev commented Oct 10, 2017

Your welcome, @tiabc

We may either cherry-pick needed commits from your branch manually

There is only one commit.

you can groom this branch yourself after #375 is merged if you have time

Yes. Let's go this way.

@tiabc
Copy link
Contributor

tiabc commented Oct 11, 2017

@oleg-raev please, proceed.

@oleg-raev
Copy link
Contributor Author

@tiabc conflicts resolved

Copy link
Contributor

@tiabc tiabc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything's great, just a number of minor fixes or questions. Can you fix or answer them, please?

)

var (
TestConfig *common.TestConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already here:

TestConfig *common.TestConfig

We use it like this:
. "github.com/status-im/status-go/testing"

@@ -25,8 +35,15 @@ type APITestSuite struct {
}

func (s *APITestSuite) SetupTest() {
var err error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's more it closer to where it's actually used. To line 43.
(if it won't be removed due to the first comment, of course)

@@ -118,3 +135,85 @@ func (s *APITestSuite) TestRaceConditions() {
time.Sleep(2 * time.Second) // so that we see some logs
s.api.StopNode() // just in case we have a node running
}

func (s *APITestSuite) TestJailStop() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestCellsRemovedAfterSwitchAccount


for i := 0; i < itersCount; i++ {
wg.Add(1)
go func(id int) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doing it in a goroutine?

s.api.JailManager().Parse(testChatID, ``)

_, err = s.api.JailManager().NewCell(testChatID)
require.NoError(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what's the meaning of this assertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, you are right. Cell created by previous call s.api.JailManager().Parse(...


func (s *JailTestSuite) TestJailStop() {
const loopLen = 5
var wg sync.WaitGroup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again: why goroutines?


c := make(chan struct{})
go func() {
defer close(c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it be easier to read without defer?

@@ -157,3 +159,49 @@ func (s *JailTestSuite) TestEventSignal() {
expectedResponse := `{"jsonrpc":"2.0","result":true}`
s.Equal(expectedResponse, response)
}

func (s *JailTestSuite) TestJailStop() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestJailCellsRemovedAfterStop

geth/api/api.go Outdated
@@ -146,11 +146,13 @@ func (api *StatusAPI) VerifyAccountPassword(keyStoreDir, address, password strin
// using provided password. Once verification is done, decrypted key is injected into Whisper (as a single identity,
// all previous identities are removed).
func (api *StatusAPI) SelectAccount(address, password string) error {
api.b.jailManager.Stop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Currently JailManager.Stop doesn't stop Jail, it just resets it to an initial state. Can you make a comment above the original method like // FIXME(oleg-raev): This method doesn't make stop, it rather resets its cells to an initial state and should be properly renamed, for example: ResetCells?

@@ -19,6 +20,10 @@ var (
baseStatusJSCode = string(static.MustAsset("testdata/jail/status.js"))
)

func TestCellTestSuite(t *testing.T) {
suite.Run(t, new(CellTestSuite))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@oleg-raev
Copy link
Contributor Author

@tiabc fixed

@@ -146,11 +146,15 @@ func (api *StatusAPI) VerifyAccountPassword(keyStoreDir, address, password strin
// using provided password. Once verification is done, decrypted key is injected into Whisper (as a single identity,
// all previous identities are removed).
func (api *StatusAPI) SelectAccount(address, password string) error {
// FIXME(oleg-raev): This method doesn't make stop, it rather resets its cells to an initial state
// and should be properly renamed, for example: ResetCells
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to the method declaration. But never mind, it's fine.

Copy link
Contributor

@influx6 influx6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@themue themue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tiabc
Copy link
Contributor

tiabc commented Oct 16, 2017

Merging without another review as this PR has been hanging too long.
There's a failure in CI caused by a timeout: https://travis-ci.org/status-im/status-go/builds/288617791#L527
These tests pass locally and I'll file a PR for this particular timeout soon.

@tiabc tiabc merged commit 2401497 into status-im:develop Oct 16, 2017
@tiabc
Copy link
Contributor

tiabc commented Oct 16, 2017

@oleg-raev thanks one more time for the successful contribution! We'll have a conversation about you joining core contributors and I'll get back to you with the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants