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

mock gundeck #554

Merged
merged 73 commits into from
Jan 15, 2019
Merged

mock gundeck #554

merged 73 commits into from
Jan 15, 2019

Conversation

fisx
Copy link
Contributor

@fisx fisx commented Dec 12, 2018

Notes for the reviewer:

  • please read commit-by-commit first, ignoring everything about the new modules MockGundeck, Push in the gundeck unit tests. then the overall changes in those two modules.
  • i am particular fond of the test gundeck's old pushAny against pushAll stuff. this gives strong evidence that the bulk-push code does not change behavior in any undesired way. :)
  • i changed some types from opaque to exposing constructors. this was mostly for convenience, i think. let me know if you want to reduce the changes there (and why).

Related: #518, #531, #546, #549

@fisx fisx force-pushed the fisx-mock-gundeck branch 4 times, most recently from c0f586b to b717a7d Compare December 19, 2018 17:22
@fisx fisx changed the title [WIP] mock gundeck mock gundeck Dec 19, 2018
@fisx
Copy link
Contributor Author

fisx commented Dec 20, 2018

updated the description. this is ready for review, but i will improve haddocks soon, feel free to wait!

@fisx fisx force-pushed the fisx-mock-gundeck branch 2 times, most recently from a5650cf to 18edeaf Compare December 21, 2018 11:33
@fisx
Copy link
Contributor Author

fisx commented Dec 21, 2018

all tests passed locally. ready for review!

libs/gundeck-types/src/Gundeck/Types/Push/V2.hs Outdated Show resolved Hide resolved
libs/types-common/src/Data/Id.hs Show resolved Hide resolved
services/gundeck/src/Gundeck/Push.hs Outdated Show resolved Hide resolved
services/gundeck/test/unit/MockGundeck.hs Outdated Show resolved Hide resolved
services/gundeck/test/unit/MockGundeck.hs Outdated Show resolved Hide resolved
services/gundeck/test/unit/MockGundeck.hs Outdated Show resolved Hide resolved
services/gundeck/test/unit/MockGundeck.hs Outdated Show resolved Hide resolved
services/gundeck/test/unit/MockGundeck.hs Outdated Show resolved Hide resolved
services/gundeck/test/unit/MockGundeck.hs Outdated Show resolved Hide resolved
@neongreen
Copy link
Contributor

I've attempted to review the actual logic here, but failed miserably – probably because I don't know well what the original Gundeck does either.

I will take another stab at it later and ask more questions.

@fisx
Copy link
Contributor Author

fisx commented Jan 7, 2019

thanks for your feedback! i processed everything but commented only where it wasn't obvious what i'm supposed to do. new commit coming up!

@fisx
Copy link
Contributor Author

fisx commented Jan 11, 2019

there is still an error uncovered by the last test coverage expansion:

TASTY_PATTERN='$NF ~ /native pushes/'  stack test . --pedantic --test --bench --no-run-benchmarks --local-bin-path=dist --fast --test-arguments=--quickcheck-replay=186970 --ghc-options=-Wwarn

pushAny correctly does not send anything; pushAll pushes to a device that shouldn't receive. if i implement connWhitelistSieve as id in mockOldSimpleWebPush, it's the opposite.

hypothesis: something about "empty list means all devices" again. maybe pushAny calls mpyPush with input where empty means full, but pushAll... (where does pushAll call mpyPush? how can the behavior of mockOldSimpleWebPush change the behavior of pushAll?!

@fisx
Copy link
Contributor Author

fisx commented Jan 14, 2019

TASTY_PATTERN='$NF ~ /native pushes/'  stack test . --pedantic --test --bench --no-run-benchmarks --local-bin-path=dist --fast --test-arguments=--quickcheck-replay=785105 --ghc-options=-Wwarn

device e is native reachable and ws reachable. it gets filtered out by pushConnections, is not sent to the websocket, and therefore gets pushed natively. that sounds quite insane, but both production implementations (with --bulk-push and without) behave that way.

is this a bug in production?

@fisx fisx changed the title [WIP] mock gundeck mock gundeck Jan 14, 2019
@@ -222,7 +256,7 @@ data Push = Push
-- REFACTOR: this make no sense any more since native push notifications have no more payload.
-- https://github.com/wireapp/wire-server/pull/546
, _pushNativeAps :: !(Maybe ApsData)
-- ^ APNs-specific metadata.
-- ^ APNs-specific metadata. REFACTOR: can this be removed?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it can!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I will remove that sentence.

natives <- mpaNativeTargets psh alreadySent
mpaPushNative notif psh natives
forM_ resp $ \((notif, psh), alreadySent) -> unless (psh ^. pushTransient) $
mpaPushNative notif psh =<< nativeTargets psh alreadySent
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this call mpaNativeTargets instead of nativeTargets ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that doesn't exist any more. instead, pushAll has a constraint that allows mocking this.

@fisx
Copy link
Contributor Author

fisx commented Jan 15, 2019

TASTY_PATTERN='$NF ~ /native pushes/'  stack test . --pedantic --test --bench --no-run-benchmarks --local-bin-path=dist --fast --test-arguments=--quickcheck-replay=785105 --ghc-options=-Wwarn

device e is native reachable and ws reachable. it gets filtered out by pushConnections, is not sent to the websocket, and therefore gets pushed natively. that sounds quite insane, but both production implementations (with --bulk-push and without) behave that way.

is this a bug in production?

Discussed this with @tiago-loureiro, and agreed it's a bug in the production code. I will revert aa0d53c and fix the behavior of pushAny and pushAll.

@fisx
Copy link
Contributor Author

fisx commented Jan 15, 2019

@neongreen wanna have a "last" look? check that 469c78a makes sense and that i didn't break compilePushResps, and see if you want to approve?

thanks for your work on this, that was quite necessary!

@@ -290,6 +292,9 @@ nativeTargets p pres =
eligibleClient _ RecipientClientsAll = True
eligibleClient a (RecipientClientsSome cs) = (a^.addrClient) `elem` cs

whitelistedOrNoWhitelist a = p^.pushConnections == mempty
Copy link
Contributor

Choose a reason for hiding this comment

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

null should work too, since both elem and null come from Foldable.

@@ -494,7 +493,9 @@ handlePushNative Push{..} = do
isOriginDevice = origin == (uid, Just cid)
isAllowedPerOriginRules =
not isOriginUser || (_pushNativeIncludeOrigin && not isOriginDevice)
when (isNative && isReachable && isAllowedPerOriginRules) $
-- Condition 5: push to cid iff (a) listed in pushConnections or (b) pushConnections is empty.
let isWhitelisted = Set.null _pushConnections || fakeConnId cid `elem` _pushConnections
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems better to have either null+elem or Set.null+Set.member, but not a mix of those.

& targetClients .~ case r^.recipientClients of
RecipientClientsAll -> []
-- clients are stored in cassandra as a list with a notification. empty list
-- is intepreted as "all clients" by 'Gundeck.Notification.Data.toNotif'.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
-- is intepreted as "all clients" by 'Gundeck.Notification.Data.toNotif'.
-- is interpreted as "all clients" by 'Gundeck.Notification.Data.toNotif'.

@neongreen
Copy link
Contributor

I haven't looked at bulk push and old web push closely, but I hope that Tiago has. If so, I'm in favor of merging this PR.

@fisx fisx merged commit 5d5bf0e into develop Jan 15, 2019
@fisx fisx deleted the fisx-mock-gundeck branch January 15, 2019 16:03
@fisx fisx mentioned this pull request Jan 24, 2019
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

3 participants