@ -45,22 +45,24 @@ func TestConfigEntry_Apply(t *testing.T) {
// wait for cross-dc queries to work
// wait for cross-dc queries to work
testrpc . WaitForLeader ( t , s2 . RPC , "dc1" )
testrpc . WaitForLeader ( t , s2 . RPC , "dc1" )
runStep ( t , "send the apply request to dc2 - it should get forwarded to dc1" , func ( t * testing . T ) {
updated := & structs . ServiceConfigEntry {
updated := & structs . ServiceConfigEntry {
Name : "foo" ,
Name : "foo" ,
}
}
// originally target this as going to dc2
args := structs . ConfigEntryRequest {
args := structs . ConfigEntryRequest {
Datacenter : "dc2" ,
Datacenter : "dc2" ,
Entry : updated ,
Entry : updated ,
}
}
out := false
var out bool
require . NoError ( t , msgpackrpc . CallWithCodec ( codec2 , "ConfigEntry.Apply" , & args , & out ) )
require . NoError ( t , msgpackrpc . CallWithCodec ( codec2 , "ConfigEntry.Apply" , & args , & out ) )
require . True ( t , out )
require . True ( t , out )
} )
var originalModifyIndex uint64
runStep ( t , "verify the entry was updated in the primary and secondary" , func ( t * testing . T ) {
// the previous RPC should not return until the primary has been updated but will return
// the previous RPC should not return until the primary has been updated but will return
// before the secondary has the data.
// before the secondary has the data.
state := s1 . fsm . State ( )
_ , entry , err := s1 . fsm . State ( ) . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
_ , entry , err := state . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
require . NoError ( t , err )
require . NoError ( t , err )
serviceConf , ok := entry . ( * structs . ServiceConfigEntry )
serviceConf , ok := entry . ( * structs . ServiceConfigEntry )
@ -70,43 +72,88 @@ func TestConfigEntry_Apply(t *testing.T) {
retry . Run ( t , func ( r * retry . R ) {
retry . Run ( t , func ( r * retry . R ) {
// wait for replication to happen
// wait for replication to happen
state := s2 . fsm . State ( )
_ , entry , err := s2 . fsm . State ( ) . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
_ , entry , err := state . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
require . NoError ( r , err )
require . NoError ( r , err )
require . NotNil ( r , entry )
require . NotNil ( r , entry )
// this test is not testing that the config entries that are replicated are correct as thats done elsewhere.
// this test is not testing that the config entries that are replicated are correct as thats done elsewhere.
} )
} )
originalModifyIndex = serviceConf . ModifyIndex
} )
updated = & structs . ServiceConfigEntry {
runStep ( t , "update the entry again in the primary" , func ( t * testing . T ) {
updated := & structs . ServiceConfigEntry {
Name : "foo" ,
Name : "foo" ,
MeshGateway : structs . MeshGatewayConfig {
MeshGateway : structs . MeshGatewayConfig {
Mode : structs . MeshGatewayModeLocal ,
Mode : structs . MeshGatewayModeLocal ,
} ,
} ,
}
}
args = structs . ConfigEntryRequest {
args : = structs . ConfigEntryRequest {
Datacenter : "dc1" ,
Datacenter : "dc1" ,
Op : structs . ConfigEntryUpsertCAS ,
Op : structs . ConfigEntryUpsertCAS ,
Entry : updated ,
Entry : updated ,
}
}
runStep ( t , "with the wrong CAS" , func ( t * testing . T ) {
var out bool
require . NoError ( t , msgpackrpc . CallWithCodec ( codec , "ConfigEntry.Apply" , & args , & out ) )
require . NoError ( t , msgpackrpc . CallWithCodec ( codec , "ConfigEntry.Apply" , & args , & out ) )
require . False ( t , out )
require . False ( t , out )
} )
args . Entry . GetRaftIndex ( ) . ModifyIndex = serviceConf . ModifyIndex
runStep ( t , "with the correct CAS" , func ( t * testing . T ) {
var out bool
args . Entry . GetRaftIndex ( ) . ModifyIndex = originalModifyIndex
require . NoError ( t , msgpackrpc . CallWithCodec ( codec , "ConfigEntry.Apply" , & args , & out ) )
require . NoError ( t , msgpackrpc . CallWithCodec ( codec , "ConfigEntry.Apply" , & args , & out ) )
require . True ( t , out )
require . True ( t , out )
} )
} )
state = s1 . fsm . State ( )
runStep ( t , "verify the entry was updated in the state store" , func ( t * testing . T ) {
_ , entry , err = state . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
_ , entry , err := s1 . fsm . State ( ) . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
require . NoError ( t , err )
require . NoError ( t , err )
serviceConf , ok = entry . ( * structs . ServiceConfigEntry )
serviceConf , ok : = entry . ( * structs . ServiceConfigEntry )
require . True ( t , ok )
require . True ( t , ok )
require . Equal ( t , structs . ServiceDefaults , serviceConf . Kind )
require . Equal ( t , structs . ServiceDefaults , serviceConf . Kind )
require . Equal ( t , "foo" , serviceConf . Name )
require . Equal ( t , "foo" , serviceConf . Name )
require . Equal ( t , "" , serviceConf . Protocol )
require . Equal ( t , "" , serviceConf . Protocol )
require . Equal ( t , structs . ServiceDefaults , serviceConf . Kind )
require . Equal ( t , structs . ServiceDefaults , serviceConf . Kind )
} )
runStep ( t , "verify no-op updates do not advance the raft indexes" , func ( t * testing . T ) {
var modifyIndex uint64
for i := 0 ; i < 3 ; i ++ {
runStep ( t , fmt . Sprintf ( "iteration %d" , i ) , func ( t * testing . T ) {
args := structs . ConfigEntryRequest {
Datacenter : "dc1" ,
Op : structs . ConfigEntryUpsert ,
Entry : & structs . ServiceConfigEntry {
Kind : structs . ServiceDefaults ,
Name : "noop" ,
Protocol : "grpc" ,
} ,
}
var out bool
require . NoError ( t , msgpackrpc . CallWithCodec ( codec , "ConfigEntry.Apply" , & args , & out ) )
require . True ( t , out )
getIndex , entry , err := s1 . fsm . State ( ) . ConfigEntry ( nil , structs . ServiceDefaults , "noop" , nil )
require . NoError ( t , err )
require . NotNil ( t , entry )
listIndex , entries , err := s1 . fsm . State ( ) . ConfigEntries ( nil , nil )
require . NoError ( t , err )
require . Len ( t , entries , 2 )
if i == 0 {
modifyIndex = entry . GetRaftIndex ( ) . ModifyIndex
} else {
require . Equal ( t , modifyIndex , entry . GetRaftIndex ( ) . ModifyIndex )
require . Equal ( t , modifyIndex , getIndex )
require . Equal ( t , modifyIndex , listIndex )
}
} )
}
} )
}
}
func TestConfigEntry_ProxyDefaultsMeshGateway ( t * testing . T ) {
func TestConfigEntry_ProxyDefaultsMeshGateway ( t * testing . T ) {
@ -623,16 +670,17 @@ func TestConfigEntry_Delete(t *testing.T) {
// wait for cross-dc queries to work
// wait for cross-dc queries to work
testrpc . WaitForLeader ( t , s2 . RPC , "dc1" )
testrpc . WaitForLeader ( t , s2 . RPC , "dc1" )
// Create a dummy service in the state store to look up.
runStep ( t , "create a dummy service in the state store to look up" , func ( t * testing . T ) {
entry := & structs . ServiceConfigEntry {
entry := & structs . ServiceConfigEntry {
Kind : structs . ServiceDefaults ,
Kind : structs . ServiceDefaults ,
Name : "foo" ,
Name : "foo" ,
}
}
state := s1 . fsm . State ( )
require . NoError ( t , s1 . fsm . State ( ) . EnsureConfigEntry ( 1 , entry ) )
require . NoError ( t , state . EnsureConfigEntry ( 1 , entry ) )
} )
runStep ( t , "verify it exists in the primary and is replicated to the secondary" , func ( t * testing . T ) {
// Verify it's there.
// Verify it's there.
_ , existing , err := state . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
_ , existing , err := s1 . fsm . S tate ( ) . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
require . NoError ( t , err )
require . NoError ( t , err )
serviceConf , ok := existing . ( * structs . ServiceConfigEntry )
serviceConf , ok := existing . ( * structs . ServiceConfigEntry )
@ -646,17 +694,24 @@ func TestConfigEntry_Delete(t *testing.T) {
require . NoError ( r , err )
require . NoError ( r , err )
require . NotNil ( r , existing )
require . NotNil ( r , existing )
} )
} )
} )
// send the delete request to dc2 - it should get forwarded to dc1.
runStep ( t , "send the delete request to dc2 - it should get forwarded to dc1" , func ( t * testing . T ) {
args := structs . ConfigEntryRequest {
args := structs . ConfigEntryRequest {
Datacenter : "dc2" ,
Datacenter : "dc2" ,
Entry : & structs . ServiceConfigEntry {
Kind : structs . ServiceDefaults ,
Name : "foo" ,
} ,
}
}
args . Entry = entry
var out structs . ConfigEntryDeleteResponse
var out struct { }
require . NoError ( t , msgpackrpc . CallWithCodec ( codec2 , "ConfigEntry.Delete" , & args , & out ) )
require . NoError ( t , msgpackrpc . CallWithCodec ( codec2 , "ConfigEntry.Delete" , & args , & out ) )
require . True ( t , out . Deleted )
} )
runStep ( t , "verify the entry was deleted in the primary and secondary" , func ( t * testing . T ) {
// Verify the entry was deleted.
// Verify the entry was deleted.
_ , existing , err = s1 . fsm . State ( ) . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
_ , existing , err : = s1 . fsm . State ( ) . ConfigEntry ( nil , structs . ServiceDefaults , "foo" , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Nil ( t , existing )
require . Nil ( t , existing )
@ -666,6 +721,20 @@ func TestConfigEntry_Delete(t *testing.T) {
require . NoError ( r , err )
require . NoError ( r , err )
require . Nil ( r , existing )
require . Nil ( r , existing )
} )
} )
} )
runStep ( t , "delete in dc1 again - should be fine" , func ( t * testing . T ) {
args := structs . ConfigEntryRequest {
Datacenter : "dc1" ,
Entry : & structs . ServiceConfigEntry {
Kind : structs . ServiceDefaults ,
Name : "foo" ,
} ,
}
var out structs . ConfigEntryDeleteResponse
require . NoError ( t , msgpackrpc . CallWithCodec ( codec , "ConfigEntry.Delete" , & args , & out ) )
require . True ( t , out . Deleted )
} )
}
}
func TestConfigEntry_DeleteCAS ( t * testing . T ) {
func TestConfigEntry_DeleteCAS ( t * testing . T ) {