Commit 6de5908a authored by Nick Craver's avatar Nick Craver

More test fixes

parent 64289d42
......@@ -24,7 +24,7 @@ public void TestPublishWithNoSubscribers()
}
}
[Fact]
[FactLongRunning]
public void TestMassivePublishWithWithoutFlush_Local()
{
using (var muxer = GetUnsecuredConnection(waitForOpen: true))
......@@ -73,7 +73,9 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption
Output.WriteLine("{2}: {0}ms (F+F) vs {1}ms (async)",
withFAF.ElapsedMilliseconds, withAsync.ElapsedMilliseconds, caption);
Assert.True(withFAF.ElapsedMilliseconds < withAsync.ElapsedMilliseconds, caption);
// We've made async so far, this test isn't really valid anymore
// So let's check they're at least within a few seconds.
Assert.True(withFAF.ElapsedMilliseconds < withAsync.ElapsedMilliseconds + 3000, caption);
}
[FactLongRunning]
......@@ -397,7 +399,7 @@ public void Issue38()
internal static void AllowReasonableTimeToPublishAndProcess()
{
Thread.Sleep(50);
Thread.Sleep(100);
}
[Fact]
......
......@@ -432,7 +432,7 @@ public void Keys(string pattern, int pageSize)
public void HashSlots(string key, int slot)
{
using (var muxer = Create(connectTimeout: 500, pause: false))
using (var muxer = Create(connectTimeout: 5000, pause: false))
{
Assert.Equal(slot, muxer.HashSlot(key));
}
......@@ -595,18 +595,20 @@ public void SimpleProfiling()
using (var conn = Create())
{
var profiler = new TestProfiler();
var key = Me();
var db = conn.GetDatabase();
db.KeyDelete(key);
conn.RegisterProfiler(profiler);
conn.BeginProfiling(profiler.MyContext);
var db = conn.GetDatabase();
db.StringSet("hello", "world");
var val = db.StringGet("hello");
db.StringSet(key, "world");
var val = db.StringGet(key);
Assert.Equal("world", val);
var msgs = conn.FinishProfiling(profiler.MyContext);
Assert.Equal(2, msgs.Count());
Assert.Contains(msgs, m => m.Command == "GET");
Assert.Contains(msgs, m => m.Command == "SET");
Assert.Equal(2, msgs.Count());
}
}
......
......@@ -62,7 +62,7 @@ public async Task ConfigVerifyReceiveConfigChangeBroadcast()
long count = sender.PublishReconfigure();
GetServer(receiver).Ping();
GetServer(receiver).Ping();
await Task.Delay(10).ConfigureAwait(false);
await Task.Delay(100).ConfigureAwait(false);
Assert.True(count == -1 || count >= 2, "subscribers");
Assert.True(Interlocked.CompareExchange(ref total, 0, 0) >= 1, "total (1st)");
......
......@@ -46,6 +46,16 @@ public override string Skip
[XunitTestCaseDiscoverer("StackExchange.Redis.Tests.TheoryDiscoverer", "StackExchange.Redis.Tests")]
public class TheoryAttribute : Xunit.TheoryAttribute { }
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class TheoryLongRunningAttribute : Xunit.TheoryAttribute
{
public override string Skip
{
get => TestConfig.Current.RunLongRunning ? base.Skip : "Config.RunLongRunning is false - skipping long test.";
set => base.Skip = value;
}
}
public class FactDiscoverer : Xunit.Sdk.FactDiscoverer
{
public FactDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnosticMessageSink) { }
......
......@@ -33,8 +33,9 @@ public void FlushFetchRandomKey()
{
using (var conn = Create(allowAdmin: true))
{
var db = conn.GetDatabase(14);
conn.GetServer(TestConfig.Current.MasterServerAndPort).FlushDatabase(14);
const int dbId = 63;
var db = conn.GetDatabase(dbId);
conn.GetServer(TestConfig.Current.MasterServerAndPort).FlushDatabase(dbId);
string anyKey = db.KeyRandom();
Assert.Null(anyKey);
......
......@@ -86,7 +86,7 @@ public void RemoveRangeByLex()
private void Equate(RedisValue[] actual, long count, params string[] expected)
{
Assert.Equal(count, expected.Length);
Assert.Equal(expected.Length, count);
Assert.Equal(expected.Length, actual.Length);
for (int i = 0; i < actual.Length; i++)
{
......@@ -94,4 +94,4 @@ private void Equate(RedisValue[] actual, long count, params string[] expected)
}
}
}
}
\ No newline at end of file
}
......@@ -41,7 +41,7 @@ public async Task MassiveBulkOpsAsync(bool withContinuation)
}
}
[Theory]
[TheoryLongRunning]
[InlineData(1)]
[InlineData(5)]
[InlineData(10)]
......
......@@ -25,14 +25,15 @@ public void Simple()
using (var conn = Create())
{
var profiler = new TestProfiler();
var key = Me();
conn.RegisterProfiler(profiler);
conn.BeginProfiling(profiler.MyContext);
var db = conn.GetDatabase(4);
db.StringSet("hello", "world");
var val = db.StringGet("hello");
db.StringSet(key, "world");
var val = db.StringGet(key);
Assert.Equal("world", (string)val);
var result=db.ScriptEvaluate(LuaScript.Prepare("return redis.call('get', @key)"), new { key = (RedisKey)"hello" });
var result=db.ScriptEvaluate(LuaScript.Prepare("return redis.call('get', @key)"), new { key = (RedisKey)key });
Assert.Equal("world", result.AsString());
var cmds = conn.FinishProfiling(profiler.MyContext);
......@@ -76,6 +77,7 @@ public void ManyThreads()
using (var conn = Create())
{
var profiler = new TestProfiler();
var prefix = Me();
conn.RegisterProfiler(profiler);
conn.BeginProfiling(profiler.MyContext);
......@@ -92,7 +94,7 @@ public void ManyThreads()
for (var j = 0; j < 1000; j++)
{
var task = db.StringSetAsync("" + j, "" + j);
var task = db.StringSetAsync(prefix + j, "" + j);
threadTasks.Add(task);
}
......@@ -140,12 +142,13 @@ public object GetContext()
}
}
[Fact]
[FactLongRunning]
public void ManyContexts()
{
using (var conn = Create())
{
var profiler = new TestProfiler2();
var prefix = Me();
conn.RegisterProfiler(profiler);
var perThreadContexts = new List<object>();
......@@ -173,8 +176,8 @@ public void ManyContexts()
for (var j = 0; j < 1000; j++)
{
allTasks.Add(db.StringGetAsync("hello" + ix));
allTasks.Add(db.StringSetAsync("hello" + ix, "world" + ix));
allTasks.Add(db.StringGetAsync(prefix + ix));
allTasks.Add(db.StringSetAsync(prefix + ix, "world" + ix));
}
Task.WaitAll(allTasks.ToArray());
......@@ -298,7 +301,7 @@ public void LeaksCollectedAndRePooled()
}
}
[Fact]
[FactLongRunning]
public void ReuseStorage()
{
const int ThreadCount = 16;
......@@ -309,6 +312,7 @@ public void ReuseStorage()
using (var conn = Create())
{
var profiler = new TestProfiler2();
var prefix = Me();
conn.RegisterProfiler(profiler);
var perThreadContexts = new List<object>();
......@@ -342,8 +346,8 @@ public void ReuseStorage()
for (var j = 0; j < 1000; j++)
{
allTasks.Add(db.StringGetAsync("hello" + ix));
allTasks.Add(db.StringSetAsync("hello" + ix, "world" + ix));
allTasks.Add(db.StringGetAsync(prefix + ix));
allTasks.Add(db.StringSetAsync(prefix + ix, "world" + ix));
}
Task.WaitAll(allTasks.ToArray());
......@@ -461,13 +465,14 @@ public object GetContext()
}
}
[Fact]
[FactLongRunning]
public void ProfilingMD_Ex1()
{
using (var c = Create())
{
ConnectionMultiplexer conn = c;
var profiler = new ToyProfiler();
var prefix = Me();
var thisGroupContext = new object();
conn.RegisterProfiler(profiler);
......@@ -484,7 +489,7 @@ public void ProfilingMD_Ex1()
for (var j = 0; j < 1000; j++)
{
var task = db.StringSetAsync("" + j, "" + j);
var task = db.StringSetAsync(prefix + j, "" + j);
threadTasks.Add(task);
}
......@@ -507,13 +512,14 @@ public void ProfilingMD_Ex1()
}
}
[Fact]
[FactLongRunning]
public void ProfilingMD_Ex2()
{
using (var c = Create())
{
ConnectionMultiplexer conn = c;
var profiler = new ToyProfiler();
var prefix = Me();
conn.RegisterProfiler(profiler);
......@@ -533,7 +539,7 @@ public void ProfilingMD_Ex2()
for (var j = 0; j < 1000; j++)
{
var task = db.StringSetAsync("" + j, "" + j);
var task = db.StringSetAsync(prefix + j, "" + j);
threadTasks.Add(task);
}
......
......@@ -96,12 +96,13 @@ public void ScanResume()
// only goes up to 3.*, so...
Skip.IfMissingFeature(conn, "Avoiding Redis on Windows", x => x.Version >= new Version(4, 0));
var db = conn.GetDatabase(DB);
var prefix = Me();
var server = GetServer(conn);
server.FlushDatabase(DB);
int i;
for (i = 0; i < 100; i++)
{
db.StringSet("ScanResume:" + i, Guid.NewGuid().ToString());
db.StringSet(prefix + ":" + i, Guid.NewGuid().ToString());
}
var expected = new HashSet<string>();
......@@ -109,7 +110,7 @@ public void ScanResume()
int snapOffset = 0, snapPageSize = 0;
i = 0;
var seq = server.Keys(DB, "ScanResume:*", pageSize: 15);
var seq = server.Keys(DB, prefix + ":*", pageSize: 15);
foreach (var key in seq)
{
if (i == 57)
......@@ -131,7 +132,7 @@ public void ScanResume()
Assert.Equal(12, snapOffset);
Assert.Equal(15, snapPageSize);
seq = server.Keys(DB, "ScanResume:*", pageSize: 15, cursor: snapCursor, pageOffset: snapOffset);
seq = server.Keys(DB, prefix + ":*", pageSize: 15, cursor: snapCursor, pageOffset: snapOffset);
var seqCur = (IScanningCursor)seq;
Assert.Equal(snapCursor, seqCur.Cursor);
Assert.Equal(snapPageSize, seqCur.PageSize);
......
......@@ -17,7 +17,7 @@ public void SScan()
{
var server = GetAnyMaster(conn);
RedisKey key = "a";
RedisKey key = Me();
var db = conn.GetDatabase();
db.KeyDelete(key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment