public async Task GetClusterVersionAsync_ReturnsValue()
        {
            var version = await _bucket.GetClusterVersionAsync();

            Assert.IsNotNull(version);
            Assert.True(version.Value >= new ClusterVersion(new Version(1, 0, 0)));

            Console.WriteLine(version);
        }
        /// <summary>
        /// Gets the version of the cluster hosting a bucket.
        /// </summary>
        /// <param name="bucket">Couchbase bucket.</param>
        /// <exception cref="ArgumentNullException"><paramref name="bucket"/> is null.</exception>
        /// <returns>The version of the cluster hosting this bucket, or 4.0.0 if unable to determine the version.</returns>
        public ClusterVersion GetVersion(IBucket bucket)
        {
            if (bucket == null)
            {
                throw new ArgumentNullException("bucket");
            }

            var cluster = bucket.Cluster;

            // First check for an existing result
            var version = CacheLookup(cluster);

            if (version != null)
            {
                return(version.Value);
            }

            var contextCache = SynchronizationContext.Current;

            SynchronizationContext.SetSynchronizationContext(null);

            try
            {
                // Only check one cluster at a time, this prevents multiple lookups during bootstrap
                lock (_lock)
                {
                    // In case the version was received while we were waiting for the lock, check for it again
                    version = CacheLookup(cluster);
                    if (version != null)
                    {
                        return(version.Value);
                    }

                    try
                    {
                        // Use the bucket to get the cluster version, in case we're using old-style bucket passwords
                        version = bucket.GetClusterVersionAsync().Result;

                        if (version != null)
                        {
                            CacheStore(cluster, version.Value);
                            return(version.Value);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Unhandled error getting cluster version", ex);

                        // Don't cache on exception, but assume 4.0 for now
                        return(new ClusterVersion(new Version(4, 0, 0)));
                    }

                    // No version information could be loaded from any node
                    var fallbackVersion = new ClusterVersion(new Version(4, 0, 0));
                    CacheStore(cluster, fallbackVersion);
                    return(fallbackVersion);
                }
            }
            finally
            {
                if (contextCache != null)
                {
                    SynchronizationContext.SetSynchronizationContext(contextCache);
                }
            }
        }