-
Notifications
You must be signed in to change notification settings - Fork 31
STITCH-1956 Fill in missing unit tests for every relevant task and clean exisiting tests. #69
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2408b2b
initial test draft
jsflax ca0cb95
Add frozen check for fail cases
jsflax d864c35
Add delete cases
jsflax bfe2d95
Most cases complete; general progress commit
jsflax 0c8a879
creating context from test harness
jsflax fd41465
Merge branch 'master' of https://github.com/mongodb/stitch-android-sd…
jsflax 0e4418d
Clean up integration tests. Consolidate logic. Allow the tests to be …
jsflax c53ecee
Pre-lint pass
jsflax 748196e
Refactor for lint
jsflax 618d0b1
Core_Methods => Proxy_Methods
jsflax 67643bd
Merge branch 'master' of https://github.com/mongodb/stitch-android-sd…
jsflax ff9b6fd
Fix testConfigure race. Lint issues
jsflax 279862e
Add comments to DataSynchronizerTestContext; add round trip test for …
jsflax 8c23fe7
Fix overaggressive IDE refactor
jsflax 4fda2e0
Add teardown for CoreSyncUnitTests
jsflax 39ada92
Add missing imports
jsflax 2234363
Add secondary tryAcquire for testConfigure
jsflax b9846f1
Ignore Proxy test class
jsflax fd02447
Addressed comments
jsflax 23e6f64
removed unnecessary wait
jsflax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,323 changes: 163 additions & 1,160 deletions
1,323
...va/com/mongodb/stitch/android/services/mongodb/remote/internal/SyncMongoClientIntTests.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...ava/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEventUnitTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.mongodb.stitch.core.services.mongodb.remote.sync.internal | ||
|
||
import com.mongodb.MongoNamespace | ||
import org.bson.BsonArray | ||
import org.bson.BsonBoolean | ||
import org.bson.BsonDocument | ||
import org.bson.BsonObjectId | ||
import org.bson.BsonString | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class ChangeEventUnitTests { | ||
private val namespace = MongoNamespace("foo", "bar") | ||
|
||
@Test | ||
fun testNew() { | ||
val expectedFullDocument = BsonDocument("foo", BsonString("bar")).append("_id", BsonObjectId()) | ||
val expectedId = BsonDocument("_id", expectedFullDocument["_id"]) | ||
val expectedOperationType = ChangeEvent.OperationType.INSERT | ||
val expectedNamespace = namespace | ||
val expectedDocumentKey = BsonDocument("_id", expectedFullDocument["_id"]) | ||
val expectedUpdateDescription = ChangeEvent.UpdateDescription( | ||
BsonDocument("foo", BsonString("bar")), | ||
listOf("baz")) | ||
|
||
val changeEvent = ChangeEvent( | ||
expectedId, | ||
expectedOperationType, | ||
expectedFullDocument, | ||
expectedNamespace, | ||
expectedDocumentKey, | ||
expectedUpdateDescription, | ||
true | ||
) | ||
|
||
assertEquals(expectedId, changeEvent.id) | ||
assertEquals(expectedOperationType, changeEvent.operationType) | ||
assertEquals(expectedFullDocument, changeEvent.fullDocument) | ||
assertEquals(expectedNamespace, changeEvent.namespace) | ||
assertEquals(expectedDocumentKey, changeEvent.documentKey) | ||
assertEquals(expectedUpdateDescription, changeEvent.updateDescription) | ||
assertEquals(true, changeEvent.hasUncommittedWrites()) | ||
} | ||
|
||
@Test | ||
fun testOperationTypeFromRemote() { | ||
assertEquals( | ||
ChangeEvent.OperationType.INSERT, | ||
ChangeEvent.OperationType.fromRemote("insert")) | ||
|
||
assertEquals( | ||
ChangeEvent.OperationType.UPDATE, | ||
ChangeEvent.OperationType.fromRemote("update")) | ||
|
||
assertEquals( | ||
ChangeEvent.OperationType.REPLACE, | ||
ChangeEvent.OperationType.fromRemote("replace")) | ||
|
||
assertEquals( | ||
ChangeEvent.OperationType.DELETE, | ||
ChangeEvent.OperationType.fromRemote("delete")) | ||
|
||
assertEquals( | ||
ChangeEvent.OperationType.UNKNOWN, | ||
ChangeEvent.OperationType.fromRemote("bad")) | ||
} | ||
|
||
@Test | ||
fun testOperationTypeToRemote() { | ||
assertEquals("insert", ChangeEvent.OperationType.INSERT.toRemote()) | ||
assertEquals("update", ChangeEvent.OperationType.UPDATE.toRemote()) | ||
assertEquals("replace", ChangeEvent.OperationType.REPLACE.toRemote()) | ||
assertEquals("delete", ChangeEvent.OperationType.DELETE.toRemote()) | ||
assertEquals("unknown", ChangeEvent.OperationType.UNKNOWN.toRemote()) | ||
} | ||
|
||
@Test | ||
fun testToBsonDocumentRoundTrip() { | ||
val expectedFullDocument = BsonDocument("foo", BsonString("bar")).append("_id", BsonObjectId()) | ||
val expectedId = BsonDocument("_id", expectedFullDocument["_id"]) | ||
val expectedOperationType = ChangeEvent.OperationType.INSERT | ||
val expectedNamespace = namespace | ||
val expectedDocumentKey = BsonDocument("_id", expectedFullDocument["_id"]) | ||
val expectedUpdateDescription = ChangeEvent.UpdateDescription( | ||
BsonDocument("foo", BsonString("bar")), | ||
listOf("baz")) | ||
|
||
val changeEvent = ChangeEvent( | ||
expectedId, | ||
expectedOperationType, | ||
expectedFullDocument, | ||
expectedNamespace, | ||
expectedDocumentKey, | ||
expectedUpdateDescription, | ||
true) | ||
|
||
val changeEventDocument = ChangeEvent.toBsonDocument(changeEvent) | ||
|
||
assertEquals(expectedFullDocument, changeEventDocument["fullDocument"]) | ||
assertEquals(expectedId, changeEventDocument["_id"]) | ||
assertEquals(BsonString(expectedOperationType.toRemote()), changeEventDocument["operationType"]) | ||
assertEquals( | ||
BsonDocument("db", BsonString(namespace.databaseName)) | ||
.append("coll", BsonString(namespace.collectionName)), | ||
changeEventDocument["ns"]) | ||
assertEquals(expectedDocumentKey, changeEventDocument["documentKey"]) | ||
assertEquals( | ||
BsonDocument("updatedFields", expectedUpdateDescription.updatedFields) | ||
.append("removedFields", BsonArray(expectedUpdateDescription.removedFields.map { BsonString(it) })), | ||
changeEventDocument["updateDescription"]) | ||
assertEquals(BsonBoolean(true), changeEventDocument["writePending"]) | ||
|
||
val changeEventFromDocument = ChangeEvent.fromBsonDocument(changeEventDocument) | ||
|
||
assertEquals(expectedFullDocument, changeEventFromDocument.fullDocument) | ||
assertEquals(expectedId, changeEventFromDocument.id) | ||
assertEquals(expectedOperationType, changeEventFromDocument.operationType) | ||
assertEquals(expectedDocumentKey, changeEventFromDocument.documentKey) | ||
assertEquals(expectedUpdateDescription.updatedFields, changeEventFromDocument.updateDescription.updatedFields) | ||
assertEquals(expectedUpdateDescription.removedFields, changeEventFromDocument.updateDescription.removedFields) | ||
assertEquals(true, changeEventFromDocument.hasUncommittedWrites()) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] is this what you think might solve the flakiness we're seeing in the configure test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is actually how the method should function. I don't believe this will solve any races.