why-not-try-calmer / test-mongo

Investigating a painful bug on the Haskell MongoDB community driver
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Alternative Test #1 #1

Open alexbevi opened 2 years ago

alexbevi commented 2 years ago

I'd like to also test this against a local replica set so I can crank up the log verbosity. Would it be possible to have a version of src/Lib.hs that doesn't use openReplicaSetSRV but instead just accepts a standard connection URI (ex: mongodb:// vs. mongodb+srv://)?

Also, when I run this against an M10 the results still fail for the Delete:

Validate
  Validate the MongoDB Atlas connector
Writes
  Ensures writes work
Delete
  Ensures deletion works FAILED [1]
Reads
  Ensures reads work FAILED [2]

Failures:

  src/Lib.hs:77:18:
  1) Delete Ensures deletion works
       uncaught exception: ErrorCall
       Prelude.foldl1': empty list

  To rerun use: --match "/Delete/Ensures deletion works/"

  src/Lib.hs:102:33:
  2) Reads Ensures reads work
       expected: 3
        but got: 75

  To rerun use: --match "/Reads/Ensures reads work/"

Randomized with seed 683037131

Finished in 0.1112 seconds
4 examples, 2 failures

Should deletions work?

why-not-try-calmer commented 2 years ago

Hi, so to your first question, you'd like to run the test but this time around after connecting using something like openReplicaSet instead of openReplicaSetSRV (same documentation page)?

Yes, deletions should work: the test for deletions fails just in case the result object expresses/encodes a failure as reported by the database server.

alexbevi commented 2 years ago

Hi, so to your first question, you'd like to run the test but this time around after connecting using something like openReplicaSet instead of openReplicaSetSRV (same documentation page)?

That is correct. I want to also test the functionality targeting a local replica set.

Yes, deletions should work: the test for deletions fails just in case the result object expresses/encodes a failure as reported by the database server.

Thanks for clarifying. I wasn't sure if this was related or not. If possible can you output the failure from the command that is returned? I'm guessing "empty list" is from the code.

why-not-try-calmer commented 2 years ago

Okay, the last build should feature these things. Use the new environment variable repname to specify a replica set name. The host name will be assigned from the already existing hname environment variable, with port 27017 used by default (set in stone for now, let me know if you need to specify the port number manually).

If you don't pass a repname, the test will fallback on the previous connection method (openReplicaSetSRV).

Notice: authentication / login works just as before, that is, you still need to pass a user name and password.

why-not-try-calmer commented 2 years ago

@alexbevi Hi Alex, does the new test suite fit the bill? :)

alexbevi commented 2 years ago

@why-not-try-calmer I'm having a hard time testing this unfortunately.

  src/Lib.hs:82:68:
  1) Validate Validate the MongoDB Atlas connector
       uncaught exception: ErrorCall
       Prelude.undefined
       CallStack (from HasCallStack):
         error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err
         undefined, called at src/Lib.hs:82:68 in test-mongo-0.1.0.0-2CYg6025HmV7LHLbRL4uJL:Lib

When I setup a local replica set and run the tests they all fail as per the above.

{"t":{"$date":"2022-08-08T06:38:47.725-04:00"},"s":"I","c":"NETWORK","id":22943,"ctx":"listener","msg":"Connection accepted","attr":{"remote":"192.168.2.13:57428","uuid":"0e6ede02-121b-4859-8922-a20a6e3eef7e","connectionId":14,"connectionCount":1}}
{"t":{"$date":"2022-08-08T06:38:47.727-04:00"},"s":"I","c":"NETWORK","id":22944,"ctx":"conn14","msg":"Connection ended","attr":{"remote":"192.168.2.13:57428","uuid":"0e6ede02-121b-4859-8922-a20a6e3eef7e","connectionId":14,"connectionCount":0}}

I see connections being established but nothing else (no auth, or handshake). I'm guessing part of the issue is my lack of knowledge around Haskell so testing takes me a lot longer :P

hname=192.168.2.13
dname=test-db
uname=user
pword=password
coll=test-collection
repname=replset

Maybe my ENVARS are just not setup correctly? (local auth with user/password as "user/password"; replica set name "replset")

why-not-try-calmer commented 2 years ago

@why-not-try-calmer I'm having a hard time testing this unfortunately.

  src/Lib.hs:82:68:
  1) Validate Validate the MongoDB Atlas connector
       uncaught exception: ErrorCall
       Prelude.undefined
       CallStack (from HasCallStack):
         error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err
         undefined, called at src/Lib.hs:82:68 in test-mongo-0.1.0.0-2CYg6025HmV7LHLbRL4uJL:Lib

When I setup a local replica set and run the tests they all fail as per the above.

{"t":{"$date":"2022-08-08T06:38:47.725-04:00"},"s":"I","c":"NETWORK","id":22943,"ctx":"listener","msg":"Connection accepted","attr":{"remote":"192.168.2.13:57428","uuid":"0e6ede02-121b-4859-8922-a20a6e3eef7e","connectionId":14,"connectionCount":1}}
{"t":{"$date":"2022-08-08T06:38:47.727-04:00"},"s":"I","c":"NETWORK","id":22944,"ctx":"conn14","msg":"Connection ended","attr":{"remote":"192.168.2.13:57428","uuid":"0e6ede02-121b-4859-8922-a20a6e3eef7e","connectionId":14,"connectionCount":0}}

I see connections being established but nothing else (no auth, or handshake). I'm guessing part of the issue is my lack of knowledge around Haskell so testing takes me a lot longer :P

hname=192.168.2.13
dname=test-db
uname=user
pword=password
coll=test-collection
repname=replset

Maybe my ENVARS are just not setup correctly? (local auth with user/password as "user/password"; replica set name "replset")

I suspect I have not understood your requirements correctly. Do you think you could write 1-2 lines of Python or Javascript or actually any high-evel programming language using an official MongoBD driver that would show me how you would like to connect?

alexbevi commented 2 years ago

Using Ruby we would typically just use a Connection URI directly such as the following:

# create client
client = Mongo::Client.new('mongodb://192.168.2.100:27017/test')
# get collection
collection = client[:foo]
# get content from collection
puts collection.aggregate([{ '$project' => { 'bar': 1, 'type': { '$type' => '$bar' } } }]).to_a

Can we do something similar with Haskell?

why-not-try-calmer commented 2 years ago

Thanks, the latest build of the test should accommodate this requirement (it's still compiling as of this message). Please take a glance once more at the README, it's been updated to reflect the changes.

Let me know if I can anything more.

alexbevi commented 2 years ago

Thanks @why-not-try-calmer - This version works for me locally which I wanted to better understand the Haskell drivers request/response flow while these tests were running. Note that this driver doesn't appear to implement the Handshake Specification so grepping logs can be more challenging in a shared environment (ex: there is no client.driver.name of Haskell being sent)

I believe I have everything I need now and will spend some time this week and next seeing how far we can get :)

why-not-try-calmer commented 2 years ago

I have a revamp of our Haskell driver in the works to implement crucial MongDB features (i.e. transactions) and perhaps I can fix the missing client.driver.name by the same token. Who gets to determine the name, this driver or MongoDB? To be sure, this is a community drive as per MongoDB classification, so I am not sure what party gets this privilege :)

alexbevi commented 2 years ago

@why-not-try-calmer it's entirely up to the person working on the driver, but the basic structure (from this section of the spec) is:

{
    hello: 1,
    helloOk: true,
    client: {
        /* OPTIONAL. If present, the "name" is REQUIRED */
        application: {
            name: "<string>"
        },
        /* REQUIRED, including all sub fields */
        driver: {
            name: "<string>",
            version: "<string>"
        },
        /* REQUIRED */
        os: {
            type: "<string>",         /* REQUIRED */
            name: "<string>",         /* OPTIONAL */
            architecture: "<string>", /* OPTIONAL */
            version: "<string>"       /* OPTIONAL */
        },
        /* OPTIONAL */
        platform: "<string>"
    }
}

As an example, this is what is logged when an application connects using the Ruby driver:

{"t":{"$date":"2022-08-09T14:28:46.178-04:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn115","msg":"client metadata","attr":{"remote":"192.168.2.13:57527","client":"conn115","doc":{"driver":{"name":"mongo-ruby-driver","version":"2.18.1"},"os":{"type":"darwin","name":"darwin20","architecture":"x86_64"},"platform":"Ruby 3.0.3, x86_64-darwin20, x86_64-apple-darwin20.6.0, M"}}}

alexbevi commented 2 years ago

@why-not-try-calmer I'm working with our teams here to setup test environments for the shared infrastructure. This takes a little while as there are various approvals required, but wanted to keep you posted that I'm still working on it ;)

why-not-try-calmer commented 2 years ago

@why-not-try-calmer I'm working with our teams here to setup test environments for the shared infrastructure. This takes a little while as there are various approvals required, but wanted to keep you posted that I'm still working on it ;)

Thanks, I appreciate!