mongo 2.7.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +39 -14
  5. data/Rakefile +1 -0
  6. data/lib/mongo/auth.rb +4 -1
  7. data/lib/mongo/client.rb +4 -3
  8. data/lib/mongo/cluster.rb +1 -1
  9. data/lib/mongo/collection/view/readable.rb +5 -2
  10. data/lib/mongo/database.rb +1 -0
  11. data/lib/mongo/error/invalid_server_preference.rb +1 -0
  12. data/lib/mongo/error/operation_failure.rb +10 -0
  13. data/lib/mongo/error/parser.rb +10 -0
  14. data/lib/mongo/event.rb +1 -2
  15. data/lib/mongo/operation/result.rb +4 -1
  16. data/lib/mongo/operation/shared/executable_transaction_label.rb +3 -1
  17. data/lib/mongo/operation/shared/sessions_supported.rb +1 -1
  18. data/lib/mongo/protocol/msg.rb +1 -1
  19. data/lib/mongo/protocol/query.rb +2 -2
  20. data/lib/mongo/retryable.rb +20 -6
  21. data/lib/mongo/server.rb +6 -0
  22. data/lib/mongo/server/connection.rb +4 -4
  23. data/lib/mongo/server/monitor/connection.rb +9 -5
  24. data/lib/mongo/server_selector/selectable.rb +86 -32
  25. data/lib/mongo/session.rb +98 -15
  26. data/lib/mongo/version.rb +1 -1
  27. data/spec/README.md +85 -0
  28. data/spec/integration/bulk_insert_spec.rb +1 -1
  29. data/spec/integration/change_stream_examples_spec.rb +3 -1
  30. data/spec/integration/change_stream_spec.rb +10 -14
  31. data/spec/integration/client_construction_spec.rb +1 -0
  32. data/spec/integration/command_monitoring_spec.rb +37 -1
  33. data/spec/integration/command_spec.rb +141 -0
  34. data/spec/integration/connection_spec.rb +4 -2
  35. data/spec/integration/cursor_reaping_spec.rb +1 -1
  36. data/spec/integration/docs_examples_spec.rb +1 -1
  37. data/spec/integration/retryable_writes_spec.rb +33 -42
  38. data/spec/integration/server_description_spec.rb +3 -3
  39. data/spec/integration/server_selector_spec.rb +79 -0
  40. data/spec/lite_spec_helper.rb +4 -2
  41. data/spec/mongo/address_spec.rb +8 -0
  42. data/spec/mongo/auth/cr_spec.rb +5 -2
  43. data/spec/mongo/auth/invalid_mechanism_spec.rb +11 -0
  44. data/spec/mongo/auth/scram/conversation_spec.rb +3 -2
  45. data/spec/mongo/auth/scram/negotiation_spec.rb +1 -2
  46. data/spec/mongo/auth/scram_spec.rb +11 -6
  47. data/spec/mongo/auth/user/view_spec.rb +13 -6
  48. data/spec/mongo/bulk_write_spec.rb +81 -104
  49. data/spec/mongo/client_construction_spec.rb +18 -7
  50. data/spec/mongo/client_spec.rb +11 -7
  51. data/spec/mongo/cluster_spec.rb +30 -1
  52. data/spec/mongo/collection/view/aggregation_spec.rb +18 -10
  53. data/spec/mongo/collection/view/change_stream_spec.rb +28 -8
  54. data/spec/mongo/collection/view/map_reduce_spec.rb +24 -10
  55. data/spec/mongo/collection/view/readable_spec.rb +37 -19
  56. data/spec/mongo/collection/view/writable_spec.rb +64 -32
  57. data/spec/mongo/collection/view_spec.rb +4 -2
  58. data/spec/mongo/collection_spec.rb +163 -73
  59. data/spec/mongo/cursor_spec.rb +5 -2
  60. data/spec/mongo/database_spec.rb +41 -19
  61. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  62. data/spec/mongo/error/parser_spec.rb +29 -0
  63. data/spec/mongo/grid/stream/write_spec.rb +2 -1
  64. data/spec/mongo/index/view_spec.rb +42 -24
  65. data/spec/mongo/operation/delete/op_msg_spec.rb +11 -7
  66. data/spec/mongo/operation/insert/op_msg_spec.rb +10 -6
  67. data/spec/mongo/operation/update/op_msg_spec.rb +10 -6
  68. data/spec/mongo/protocol/compressed_spec.rb +1 -1
  69. data/spec/mongo/protocol/msg_spec.rb +1 -1
  70. data/spec/mongo/server/app_metadata_spec.rb +2 -1
  71. data/spec/mongo/server/connection_auth_spec.rb +1 -1
  72. data/spec/mongo/server/monitor/connection_spec.rb +42 -0
  73. data/spec/mongo/server_selector_spec.rb +17 -0
  74. data/spec/mongo/server_spec.rb +110 -0
  75. data/spec/mongo/session/session_pool_spec.rb +1 -1
  76. data/spec/mongo/session_spec.rb +1 -1
  77. data/spec/mongo/session_transaction_spec.rb +162 -1
  78. data/spec/mongo/socket/ssl_spec.rb +14 -7
  79. data/spec/mongo/uri/srv_protocol_spec.rb +41 -34
  80. data/spec/spec_helper.rb +3 -191
  81. data/spec/spec_tests/change_streams_spec.rb +3 -6
  82. data/spec/spec_tests/data/transactions/abort.yml +3 -1
  83. data/spec/spec_tests/data/transactions/commit.yml +4 -3
  84. data/spec/spec_tests/data/transactions/error-labels.yml +17 -13
  85. data/spec/spec_tests/data/transactions/read-concern.yml +611 -0
  86. data/spec/spec_tests/data/transactions/retryable-commit.yml +126 -21
  87. data/spec/spec_tests/data/transactions_api/callback-aborts.yml +42 -39
  88. data/spec/spec_tests/data/transactions_api/callback-commits.yml +52 -50
  89. data/spec/spec_tests/data/transactions_api/callback-retry.yml +33 -31
  90. data/spec/spec_tests/data/transactions_api/commit-retry.yml +42 -39
  91. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +13 -12
  92. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +15 -26
  93. data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +25 -33
  94. data/spec/spec_tests/data/transactions_api/commit.yml +44 -42
  95. data/spec/spec_tests/data/transactions_api/transaction-options.yml +25 -23
  96. data/spec/spec_tests/max_staleness_spec.rb +2 -0
  97. data/spec/spec_tests/retryable_writes_spec.rb +2 -6
  98. data/spec/spec_tests/sdam_spec.rb +2 -0
  99. data/spec/spec_tests/server_selection_spec.rb +3 -0
  100. data/spec/spec_tests/transactions_api_spec.rb +7 -1
  101. data/spec/spec_tests/transactions_spec.rb +6 -0
  102. data/spec/spec_tests/uri_options_spec.rb +4 -26
  103. data/spec/support/certificates/ca.pem +21 -16
  104. data/spec/support/certificates/client.pem +90 -90
  105. data/spec/support/certificates/client_cert.pem +21 -20
  106. data/spec/support/certificates/client_key.pem +27 -28
  107. data/spec/support/certificates/client_key_encrypted.pem +26 -26
  108. data/spec/support/certificates/crl.pem +10 -8
  109. data/spec/support/certificates/crl_client_revoked.pem +11 -10
  110. data/spec/support/certificates/server.pem +48 -33
  111. data/spec/support/change_streams.rb +12 -32
  112. data/spec/support/client_registry.rb +12 -1
  113. data/spec/support/cluster_config.rb +48 -2
  114. data/spec/support/common_shortcuts.rb +73 -7
  115. data/spec/support/connection_string.rb +0 -3
  116. data/spec/support/constraints.rb +87 -22
  117. data/spec/support/crud.rb +2 -1
  118. data/spec/support/shared/server_selector.rb +0 -28
  119. data/spec/support/shared/session.rb +25 -14
  120. data/spec/support/transactions.rb +4 -8
  121. data/spec/support/transactions/operation.rb +26 -4
  122. data/spec/support/transactions/verifier.rb +5 -2
  123. metadata +496 -488
  124. metadata.gz.sig +5 -2
  125. data/spec/support/certificates/password_protected.pem +0 -51
@@ -103,7 +103,8 @@ describe Mongo::Socket::SSL do
103
103
  end
104
104
  end
105
105
 
106
- context 'when certificate and an encrypted key are provided as strings', if: testing_ssl_locally? do
106
+ context 'when certificate and an encrypted key are provided as strings' do
107
+ require_local_tls
107
108
 
108
109
  let(:options) do
109
110
  {
@@ -321,7 +322,8 @@ describe Mongo::Socket::SSL do
321
322
  end
322
323
  end
323
324
 
324
- context 'when ruby version is < 2.4.1', if: (RUBY_VERSION < '2.4.1') do
325
+ context 'when ruby version is < 2.4.1' do
326
+ ruby_version_lt '2.4.1'
325
327
 
326
328
  context 'when a key is passed, but it is not of the right type' do
327
329
 
@@ -347,7 +349,8 @@ describe Mongo::Socket::SSL do
347
349
  # a NoMethodError because #private? is attempted to be called on the key.
348
350
  # In jruby 9.2 a TypeError is raised.
349
351
  # In jruby 9.1 a OpenSSL::PKey::PKeyError is raised.
350
- context 'when ruby version is >= 2.4.1', if: (RUBY_VERSION >= '2.4.1') do
352
+ context 'when ruby version is >= 2.4.1' do
353
+ ruby_version_gte '2.4.1'
351
354
 
352
355
  context 'when a key is passed, but it is not of the right type' do
353
356
 
@@ -415,7 +418,8 @@ describe Mongo::Socket::SSL do
415
418
  end
416
419
  end
417
420
 
418
- context 'when a CA certificate is provided', if: testing_ssl_locally? do
421
+ context 'when a CA certificate is provided' do
422
+ require_local_tls
419
423
 
420
424
  context 'as a path to a file' do
421
425
 
@@ -531,7 +535,8 @@ describe Mongo::Socket::SSL do
531
535
  end
532
536
  end
533
537
 
534
- context 'when a CA certificate is not provided', if: testing_ssl_locally? do
538
+ context 'when a CA certificate is not provided' do
539
+ require_local_tls
535
540
 
536
541
  let(:options) do
537
542
  super().merge(
@@ -549,7 +554,8 @@ describe Mongo::Socket::SSL do
549
554
  end
550
555
  end
551
556
 
552
- context 'when ssl_verify is not specified', if: testing_ssl_locally? do
557
+ context 'when ssl_verify is not specified' do
558
+ require_local_tls
553
559
 
554
560
  let(:options) do
555
561
  super().merge(
@@ -566,7 +572,8 @@ describe Mongo::Socket::SSL do
566
572
  end
567
573
  end
568
574
 
569
- context 'when ssl_verify is true', if: testing_ssl_locally? do
575
+ context 'when ssl_verify is true' do
576
+ require_local_tls
570
577
 
571
578
  let(:options) do
572
579
  super().merge(
@@ -5,6 +5,17 @@ describe Mongo::URI::SRVProtocol do
5
5
  let(:scheme) { 'mongodb+srv://' }
6
6
  let(:uri) { described_class.new(string) }
7
7
 
8
+ before(:all) do
9
+ # Since these tests assert on warnings being produced,
10
+ # close clients to ensure background threads do not interfere with
11
+ # their warnings.
12
+ ClientRegistry.instance.close_all_clients
13
+ end
14
+
15
+ let(:client) do
16
+ new_local_client(string, monitoring_io: false)
17
+ end
18
+
8
19
  describe 'invalid uris' do
9
20
 
10
21
  context 'when there is more than one hostname' do
@@ -346,7 +357,7 @@ describe Mongo::URI::SRVProtocol do
346
357
  end
347
358
 
348
359
  it 'sets the options on a client created with the uri' do
349
- expect(new_local_client(string).options[:write]).to eq(concern)
360
+ expect(client.options[:write]).to eq(concern)
350
361
  end
351
362
  end
352
363
 
@@ -359,7 +370,7 @@ describe Mongo::URI::SRVProtocol do
359
370
  end
360
371
 
361
372
  it 'sets the options on a client created with the uri' do
362
- expect(new_local_client(string).options[:write]).to eq(concern)
373
+ expect(client.options[:write]).to eq(concern)
363
374
  end
364
375
  end
365
376
 
@@ -372,7 +383,7 @@ describe Mongo::URI::SRVProtocol do
372
383
  end
373
384
 
374
385
  it 'sets the options on a client created with the uri' do
375
- expect(new_local_client(string).options[:write]).to eq(concern)
386
+ expect(client.options[:write]).to eq(concern)
376
387
  end
377
388
  end
378
389
 
@@ -385,7 +396,7 @@ describe Mongo::URI::SRVProtocol do
385
396
  end
386
397
 
387
398
  it 'sets the options on a client created with the uri' do
388
- expect(new_local_client(string).options[:write]).to eq(concern)
399
+ expect(client.options[:write]).to eq(concern)
389
400
  end
390
401
  end
391
402
 
@@ -399,7 +410,7 @@ describe Mongo::URI::SRVProtocol do
399
410
  end
400
411
 
401
412
  it 'sets the options on a client created with the uri' do
402
- expect(new_local_client(string).options[:write]).to eq(concern)
413
+ expect(client.options[:write]).to eq(concern)
403
414
  end
404
415
  end
405
416
  end
@@ -416,7 +427,7 @@ describe Mongo::URI::SRVProtocol do
416
427
  end
417
428
 
418
429
  it 'sets the options on a client created with the uri' do
419
- expect(new_local_client(string).options[:read]).to eq(read)
430
+ expect(client.options[:read]).to eq(read)
420
431
  end
421
432
  end
422
433
 
@@ -429,7 +440,7 @@ describe Mongo::URI::SRVProtocol do
429
440
  end
430
441
 
431
442
  it 'sets the options on a client created with the uri' do
432
- expect(new_local_client(string).options[:read]).to eq(read)
443
+ expect(client.options[:read]).to eq(read)
433
444
  end
434
445
  end
435
446
 
@@ -442,7 +453,7 @@ describe Mongo::URI::SRVProtocol do
442
453
  end
443
454
 
444
455
  it 'sets the options on a client created with the uri' do
445
- expect(new_local_client(string).options[:read]).to eq(read)
456
+ expect(client.options[:read]).to eq(read)
446
457
  end
447
458
  end
448
459
 
@@ -455,7 +466,7 @@ describe Mongo::URI::SRVProtocol do
455
466
  end
456
467
 
457
468
  it 'sets the options on a client created with the uri' do
458
- expect(new_local_client(string).options[:read]).to eq(read)
469
+ expect(client.options[:read]).to eq(read)
459
470
  end
460
471
  end
461
472
 
@@ -468,7 +479,7 @@ describe Mongo::URI::SRVProtocol do
468
479
  end
469
480
 
470
481
  it 'sets the options on a client created with the uri' do
471
- expect(new_local_client(string).options[:read]).to eq(read)
482
+ expect(client.options[:read]).to eq(read)
472
483
  end
473
484
  end
474
485
  end
@@ -489,7 +500,7 @@ describe Mongo::URI::SRVProtocol do
489
500
  end
490
501
 
491
502
  it 'sets the options on a client created with the uri' do
492
- expect(new_local_client(string).options[:read]).to eq(read)
503
+ expect(client.options[:read]).to eq(read)
493
504
  end
494
505
  end
495
506
 
@@ -507,7 +518,7 @@ describe Mongo::URI::SRVProtocol do
507
518
  end
508
519
 
509
520
  it 'sets the options on a client created with the uri' do
510
- expect(new_local_client(string).options[:read]).to eq(read)
521
+ expect(client.options[:read]).to eq(read)
511
522
  end
512
523
  end
513
524
  end
@@ -527,7 +538,7 @@ describe Mongo::URI::SRVProtocol do
527
538
  end
528
539
 
529
540
  it 'sets the options on a client created with the uri' do
530
- expect(new_local_client(string).options[:read]).to eq(read)
541
+ expect(client.options[:read]).to eq(read)
531
542
  end
532
543
 
533
544
  context 'when the read preference and max staleness combination is invalid' do
@@ -540,7 +551,7 @@ describe Mongo::URI::SRVProtocol do
540
551
 
541
552
  it 'raises an exception when read preference is accessed on the client' do
542
553
  expect {
543
- new_local_client(string).server_selector
554
+ client.server_selector
544
555
  }.to raise_exception(Mongo::Error::InvalidServerPreference)
545
556
  end
546
557
  end
@@ -552,7 +563,7 @@ describe Mongo::URI::SRVProtocol do
552
563
  end
553
564
 
554
565
  it 'does not raise an exception until the read preference is used' do
555
- expect(new_local_client(string).read_preference).to eq(BSON::Document.new(mode: :secondary, max_staleness: 89))
566
+ expect(client.read_preference).to eq(BSON::Document.new(mode: :secondary, max_staleness: 89))
556
567
  end
557
568
  end
558
569
  end
@@ -567,7 +578,7 @@ describe Mongo::URI::SRVProtocol do
567
578
  end
568
579
 
569
580
  it 'sets the options on a client created with the uri' do
570
- expect(new_local_client(string).options[:replica_set]).to eq(rs_name)
581
+ expect(client.options[:replica_set]).to eq(rs_name)
571
582
  end
572
583
  end
573
584
 
@@ -583,7 +594,7 @@ describe Mongo::URI::SRVProtocol do
583
594
  end
584
595
 
585
596
  it 'sets the options on a client created with the uri' do
586
- expect(new_local_client(string).options[:auth_mech]).to eq(expected)
597
+ expect(client.options[:auth_mech]).to eq(expected)
587
598
  end
588
599
 
589
600
  it 'is case-insensitive' do
@@ -600,7 +611,7 @@ describe Mongo::URI::SRVProtocol do
600
611
  end
601
612
 
602
613
  it 'sets the options on a client created with the uri' do
603
- expect(new_local_client(string).options[:auth_mech]).to eq(expected)
614
+ expect(client.options[:auth_mech]).to eq(expected)
604
615
  end
605
616
 
606
617
  it 'is case-insensitive' do
@@ -617,7 +628,7 @@ describe Mongo::URI::SRVProtocol do
617
628
  end
618
629
 
619
630
  it 'sets the options on a client created with the uri' do
620
- expect(new_local_client(string).options[:auth_mech]).to eq(expected)
631
+ expect(client.options[:auth_mech]).to eq(expected)
621
632
  end
622
633
 
623
634
  it 'is case-insensitive' do
@@ -634,7 +645,7 @@ describe Mongo::URI::SRVProtocol do
634
645
  end
635
646
 
636
647
  it 'sets the options on a client created with the uri' do
637
- expect(new_local_client(string).options[:auth_mech]).to eq(expected)
648
+ expect(client.options[:auth_mech]).to eq(expected)
638
649
  end
639
650
 
640
651
  it 'is case-insensitive' do
@@ -651,7 +662,7 @@ describe Mongo::URI::SRVProtocol do
651
662
  end
652
663
 
653
664
  it 'sets the options on a client created with the uri' do
654
- expect(new_local_client(string).options[:auth_mech]).to eq(expected)
665
+ expect(client.options[:auth_mech]).to eq(expected)
655
666
  end
656
667
 
657
668
  it 'is case-insensitive' do
@@ -679,7 +690,7 @@ describe Mongo::URI::SRVProtocol do
679
690
  end
680
691
 
681
692
  it 'sets the options on a client created with the uri' do
682
- expect(new_local_client(string).options[:auth_source]).to eq(source)
693
+ expect(client.options[:auth_source]).to eq(source)
683
694
  end
684
695
  end
685
696
 
@@ -692,7 +703,7 @@ describe Mongo::URI::SRVProtocol do
692
703
  end
693
704
 
694
705
  it 'sets the options on a client created with the uri' do
695
- expect(new_local_client(string).options[:auth_source]).to eq(expected)
706
+ expect(client.options[:auth_source]).to eq(expected)
696
707
  end
697
708
  end
698
709
  end
@@ -712,7 +723,7 @@ describe Mongo::URI::SRVProtocol do
712
723
  end
713
724
 
714
725
  it 'sets the options on a client created with the uri' do
715
- expect(new_local_client(string).options[:auth_mech_properties]).to eq(expected)
726
+ expect(client.options[:auth_mech_properties]).to eq(expected)
716
727
  end
717
728
  end
718
729
 
@@ -728,7 +739,7 @@ describe Mongo::URI::SRVProtocol do
728
739
  end
729
740
 
730
741
  it 'sets the options on a client created with the uri' do
731
- expect(new_local_client(string).options[:auth_mech_properties]).to eq(expected)
742
+ expect(client.options[:auth_mech_properties]).to eq(expected)
732
743
  end
733
744
  end
734
745
 
@@ -746,7 +757,7 @@ describe Mongo::URI::SRVProtocol do
746
757
  end
747
758
 
748
759
  it 'sets the options on a client created with the uri' do
749
- expect(new_local_client(string).options[:auth_mech_properties]).to eq(expected)
760
+ expect(client.options[:auth_mech_properties]).to eq(expected)
750
761
  end
751
762
  end
752
763
 
@@ -772,7 +783,7 @@ describe Mongo::URI::SRVProtocol do
772
783
  end
773
784
 
774
785
  it 'sets the options on a client created with the uri' do
775
- expect(new_local_client(string).options[:auth_mech_properties]).to eq(expected)
786
+ expect(client.options[:auth_mech_properties]).to eq(expected)
776
787
  end
777
788
  end
778
789
  end
@@ -900,7 +911,7 @@ describe Mongo::URI::SRVProtocol do
900
911
  let(:options) { "appname=srv_test" }
901
912
 
902
913
  it 'sets the app name on the client' do
903
- expect(new_local_client(string).options[:app_name]).to eq(:srv_test)
914
+ expect(client.options[:app_name]).to eq(:srv_test)
904
915
  end
905
916
  end
906
917
 
@@ -908,17 +919,13 @@ describe Mongo::URI::SRVProtocol do
908
919
  let(:options) { "compressors=zlib" }
909
920
 
910
921
  it 'sets the compressors as an array on the client' do
911
- expect(new_local_client(string).options[:compressors]).to eq(['zlib'])
922
+ expect(client.options[:compressors]).to eq(['zlib'])
912
923
  end
913
924
  end
914
925
 
915
926
  context 'when a non-supported compressors option is provided' do
916
927
  let(:options) { "compressors=snoopy" }
917
928
 
918
- let(:client) do
919
- new_local_client(string)
920
- end
921
-
922
929
  it 'sets no compressors on the client and warns' do
923
930
  expect(Mongo::Logger.logger).to receive(:warn)
924
931
  expect(client.options[:compressors]).to be_nil
@@ -929,7 +936,7 @@ describe Mongo::URI::SRVProtocol do
929
936
  let(:options) { "zlibCompressionLevel=6" }
930
937
 
931
938
  it 'sets the zlib compression level on the client' do
932
- expect(new_local_client(string).options[:zlib_compression_level]).to eq(6)
939
+ expect(client.options[:zlib_compression_level]).to eq(6)
933
940
  end
934
941
  end
935
942
  end
@@ -1,80 +1,3 @@
1
- # The tests run against a MongoDB cluster which is
2
- # configured and started externally to the test suite. This allows
3
- # running the entire test suite against, for example, a standalone
4
- # mongod as well as a replica set. The flip side to this is the
5
- # test suite will not work without a running mongo cluster, and
6
- # tests which are not applicable to or cannot be performed on the
7
- # running mongo cluster are skipped.
8
- #
9
- # Not only does the test suite require an externally launched cluster,
10
- # the test suite must also be told how the cluster is configured
11
- # via MONGODB_URI, TOPOLOGY, MONGODB_ADDRESSES, RS_ENABLED, RS_NAME and
12
- # SHARDED_ENABLED environment variables.
13
- #
14
- # The test suite does not validate that it is able to successfully connect
15
- # to the cluster prior to running the tests. If a connection fails entirely,
16
- # the clue is generally failures to invoke methods on nil.
17
- # However, it is also possible to establish a connection to a cluster which
18
- # is not quite correctly configured. The result is usually a mass of test
19
- # failures that are indistinguishable from legitimate failures.
20
- #
21
- # Additionally some of the tests assume that the seed list (given in
22
- # MONGODB_URI or MONGODB_ADDRESSES) encompasses all servers in the cluster,
23
- # and will fail when MONGODB_URI includes only one host of a replica set.
24
- # It is best to include all hosts of the cluster in MONGODB_URI and
25
- # MONGODB_ADDRESSES.
26
- #
27
- # The test suite seems to have issues connecting to a replica set
28
- # via IP addresses if the replica set hosts are defined with hostnames
29
- # (i.e., 127.0.0.1 vs localhost). Try to exactly match the contents of
30
- # MONGODB_URI and `rs.isMaster()` output, either by adjusting MONGODB_URI
31
- # or by reconfiguring the replica set.
32
- #
33
- # In order to run spec tests, the mongo cluster needs to have fail points
34
- # enabled. This is accomplished by starting mongod with the following option:
35
- # --setParameter enableTestCommands=1
36
- #
37
- # Use the following environment variables to configure the tests:
38
- #
39
- # CLIENT_DEBUG: Show debug messages from the client.
40
- # CLIENT_DEBUG=1
41
- #
42
- # MONGODB_URI: Connection string to use. This must be a valid MongoDB URI;
43
- # mongodb:// and mongodb+srv:// are both supported.
44
- # RS_ENABLED and SHARDED_ENABLED are NOT honored if using MONGODB_URI -
45
- # specify replica set name in the URI and to specify a sharded topology
46
- # set TOPOLOGY=sharded_cluster environment variable.
47
- # MONGODB_URI=mongodb://127.0.0.1:27001/?replicaSet=test
48
- # MONGODB_URI=mongodb://127.0.0.1:27001,127.0.0.1:27002/ TOPOLOGY=sharded_cluster
49
- #
50
- # MONGODB_ADDRESSES: Specify addresses to connect to. Use RS_ENABLED,
51
- # RS_NAME and SHARDED_ENABLED to configure the topology.
52
- # MONGODB_ADDRESSES=127.0.0.1:27017,127.0.0.1:27018
53
- # MONGODB_ADDRESSES=127.0.0.1:27017,127.0.0.1:27018 RS_ENABLED=1
54
- # MONGODB_ADDRESSES=127.0.0.1:27017,127.0.0.1:27018 RS_ENABLED=1 RS_NAME=test
55
- # MONGODB_ADDRESSES=127.0.0.1:27017,127.0.0.1:27018 SHARDED_ENABLED=1
56
- #
57
- # RS_ENABLED: Instruct the test suite to connect to a replica set.
58
- # RS_ENABLED is only honored when not using MONGODB_URI; to connect to a
59
- # replica set with MONGODB_URI, specify the replica set name in the URI
60
- # (despite the Ruby driver performing topology discovery by default, it
61
- # doesn't do so in the test suite).
62
- # RS_NAME can be given to specify the replica set name; the default is
63
- # ruby-driver-rs.
64
- # RS_ENABLED=1
65
- # RS_ENABLED=1 RS_NAME=test
66
- #
67
- # SHARDED_ENABLED: Instruct the test suite to connect to the sharded cluster.
68
- # Set MONGODB_URI appropriately as well.
69
- # SHARDED_ENABLED=1
70
- #
71
- # SSL_ENABLED: Instruct the test suite to connect to the cluster via SSL.
72
- # SSL_ENABLED=1
73
- # # Also acceptable:
74
- # SSL=ssl
75
- #
76
- # Note: SSL can also be enabled by giving ssl=true in the MONGODB_URI options.
77
-
78
1
  require 'lite_spec_helper'
79
2
 
80
3
  # Replica set name can be overridden via replicaSet parameter in MONGODB_URI
@@ -93,29 +16,13 @@ RSpec.configure do |config|
93
16
  config.include(Authorization)
94
17
  config.extend(Constraints)
95
18
 
96
- config.after(:each) do
97
- if rand < 0.01
98
- close_local_clients
19
+ config.before(:all) do
20
+ if ClusterConfig.instance.fcv_ish >= '3.6'
21
+ kill_all_server_sessions
99
22
  end
100
23
  end
101
24
  end
102
25
 
103
- # Determine whether the test clients are connecting to a standalone.
104
- #
105
- # @since 2.0.0
106
- def standalone?
107
- $mongo_client ||= initialize_scanned_client!
108
- $standalone ||= $mongo_client.cluster.servers.first.standalone?
109
- end
110
-
111
- # Determine whether the test clients are connecting to a replica set.
112
- #
113
- # @since 2.0.0
114
- def replica_set?
115
- $mongo_client ||= initialize_scanned_client!
116
- $replica_set ||= $mongo_client.cluster.replica_set?
117
- end
118
-
119
26
  # Determine whether the test clients are connecting to a sharded cluster
120
27
  # or a single mongos.
121
28
  #
@@ -145,41 +52,6 @@ def single_mongos?
145
52
  ClusterConfig.instance.single_server? && ClusterConfig.instance.mongos?
146
53
  end
147
54
 
148
- # For instances where behavior is different on different versions, we need to
149
- # determine in the specs if we are 3.6 or higher.
150
- #
151
- # @since 2.5.0
152
- def op_msg_enabled?
153
- $op_msg_enabled ||= scanned_client_server!.features.op_msg_enabled?
154
- end
155
- alias :change_stream_enabled? :op_msg_enabled?
156
- alias :sessions_enabled? :op_msg_enabled?
157
-
158
- # Whether change streams can be tested. Change streams are available on server versions 3.6
159
- # and higher and when connected to a replica set.
160
- #
161
- # @since 2.5.0
162
- def test_change_streams?
163
- !BSON::Environment.jruby? && change_stream_enabled? & replica_set?
164
- end
165
-
166
- # For instances where behavior is different on different versions, we need to
167
- # determine in the specs if we are 3.6 or higher.
168
- #
169
- # @since 2.5.0
170
- def array_filters_enabled?
171
- $array_filters_enabled ||= scanned_client_server!.features.array_filters_enabled?
172
- end
173
-
174
-
175
- # For instances where behavior is different on different versions, we need to
176
- # determine in the specs if we are 3.4 or higher.
177
- #
178
- # @since 2.4.0
179
- def collation_enabled?
180
- $collation_enabled ||= scanned_client_server!.features.collation_enabled?
181
- end
182
-
183
55
  # For instances where behavior is different on different versions, we need to
184
56
  # determine in the specs if we are 3.2 or higher.
185
57
  #
@@ -188,14 +60,6 @@ def find_command_enabled?
188
60
  $find_command_enabled ||= scanned_client_server!.features.find_command_enabled?
189
61
  end
190
62
 
191
- # For instances where behavior is different on different versions, we need to
192
- # determine in the specs if we are 2.7 or higher.
193
- #
194
- # @since 2.0.0
195
- def list_command_enabled?
196
- $list_command_enabled ||= scanned_client_server!.features.list_indexes_enabled?
197
- end
198
-
199
63
  # For instances where behavior is different on different versions, we need to
200
64
  # determine in the specs if we are 4.0 or higher.
201
65
  #
@@ -204,58 +68,6 @@ def scram_sha_256_enabled?
204
68
  $scram_sha_256_enabled ||= scanned_client_server!.features.scram_sha_256_enabled?
205
69
  end
206
70
 
207
- # Is the test suite running locally (not on Travis).
208
- #
209
- # @since 2.1.0
210
- def testing_ssl_locally?
211
- SpecConfig.instance.ssl? && !(ENV['CI'])
212
- end
213
-
214
- # Is the test suite using compression.
215
- #
216
- # @since 2.5.0
217
- def compression_enabled?
218
- !SpecConfig.instance.compressors.nil?
219
- end
220
-
221
- # Is the test suite testing compression.
222
- # Requires that the server supports compression and compression is used by the test client.
223
- #
224
- # @since 2.5.0
225
- def testing_compression?
226
- compression_enabled? && op_msg_enabled?
227
- end
228
-
229
- alias :scram_sha_1_enabled? :list_command_enabled?
230
-
231
- # Try running a command on the admin database to see if the mongod was started with auth.
232
- #
233
- # @since 2.2.0
234
- def auth_enabled?
235
- if auth = ENV['AUTH']
236
- auth == 'auth'
237
- else
238
- $mongo_client ||= initialize_scanned_client!
239
- begin
240
- $mongo_client.use(:admin).command(getCmdLineOpts: 1).first["argv"].include?("--auth")
241
- rescue => e
242
- e.message =~ /(not authorized)|(unauthorized)|(no users authenticated)|(requires authentication)/
243
- end
244
- end
245
- end
246
-
247
- def need_to_skip_on_sharded_auth_40?
248
- sharded? && auth_enabled? && scram_sha_256_enabled?
249
- end
250
-
251
- # Can the driver specify a write concern that won't be overridden? (mongos 4.0+ overrides the write
252
- # concern)
253
- #
254
- # @since 2.6.0
255
- def can_set_write_concern?
256
- !sharded? || !scram_sha_256_enabled?
257
- end
258
-
259
71
  # Initializes a basic scanned client to do an ismaster check.
260
72
  #
261
73
  # @since 2.0.0