1# Tests for fixing migrating slot at all stages:
2# 1. when migration is half inited on "migrating" node
3# 2. when migration is half inited on "importing" node
4# 3. migration inited, but not finished
5# 4. migration is half finished on "migrating" node
6# 5. migration is half finished on "importing" node
7
8# TODO: Test is currently disabled until it is stabilized (fixing the test
9# itself or real issues in Redis).
10
11if {false} {
12source "../tests/includes/init-tests.tcl"
13source "../tests/includes/utils.tcl"
14
15test "Create a 2 nodes cluster" {
16    create_cluster 2 0
17    config_set_all_nodes cluster-allow-replica-migration no
18}
19
20test "Cluster is up" {
21    assert_cluster_state ok
22}
23
24set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
25catch {unset nodefrom}
26catch {unset nodeto}
27
28proc reset_cluster {} {
29    uplevel 1 {
30        $cluster refresh_nodes_map
31        array set nodefrom [$cluster masternode_for_slot 609]
32        array set nodeto [$cluster masternode_notfor_slot 609]
33    }
34}
35
36reset_cluster
37
38$cluster set aga xyz
39
40test "Half init migration in 'migrating' is fixable" {
41    assert_equal {OK} [$nodefrom(link) cluster setslot 609 migrating $nodeto(id)]
42    fix_cluster $nodefrom(addr)
43    assert_equal "xyz" [$cluster get aga]
44}
45
46test "Half init migration in 'importing' is fixable" {
47    assert_equal {OK} [$nodeto(link) cluster setslot 609 importing $nodefrom(id)]
48    fix_cluster $nodefrom(addr)
49    assert_equal "xyz" [$cluster get aga]
50}
51
52test "Init migration and move key" {
53    assert_equal {OK} [$nodefrom(link) cluster setslot 609 migrating $nodeto(id)]
54    assert_equal {OK} [$nodeto(link) cluster setslot 609 importing $nodefrom(id)]
55    assert_equal {OK} [$nodefrom(link) migrate $nodeto(host) $nodeto(port) aga 0 10000]
56    wait_for_cluster_propagation
57    assert_equal "xyz" [$cluster get aga]
58    fix_cluster $nodefrom(addr)
59    assert_equal "xyz" [$cluster get aga]
60}
61
62reset_cluster
63
64test "Move key again" {
65    wait_for_cluster_propagation
66    assert_equal {OK} [$nodefrom(link) cluster setslot 609 migrating $nodeto(id)]
67    assert_equal {OK} [$nodeto(link) cluster setslot 609 importing $nodefrom(id)]
68    assert_equal {OK} [$nodefrom(link) migrate $nodeto(host) $nodeto(port) aga 0 10000]
69    wait_for_cluster_propagation
70    assert_equal "xyz" [$cluster get aga]
71}
72
73test "Half-finish migration" {
74    # half finish migration on 'migrating' node
75    assert_equal {OK} [$nodefrom(link) cluster setslot 609 node $nodeto(id)]
76    fix_cluster $nodefrom(addr)
77    assert_equal "xyz" [$cluster get aga]
78}
79
80reset_cluster
81
82test "Move key back" {
83    # 'aga' key is in 609 slot
84    assert_equal {OK} [$nodefrom(link) cluster setslot 609 migrating $nodeto(id)]
85    assert_equal {OK} [$nodeto(link) cluster setslot 609 importing $nodefrom(id)]
86    assert_equal {OK} [$nodefrom(link) migrate $nodeto(host) $nodeto(port) aga 0 10000]
87    assert_equal "xyz" [$cluster get aga]
88}
89
90test "Half-finish importing" {
91    # Now we half finish 'importing' node
92    assert_equal {OK} [$nodeto(link) cluster setslot 609 node $nodeto(id)]
93    fix_cluster $nodefrom(addr)
94    assert_equal "xyz" [$cluster get aga]
95}
96
97config_set_all_nodes cluster-allow-replica-migration yes
98}
99