mirror of
https://github.com/openziti/ziti.git
synced 2026-09-11 13:29:03 +00:00
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package model
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// A simple test to check for failure of alignment on atomic operations for 64 bit variables in a struct
|
|
func Test64BitAlignment(t *testing.T) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("One of the variables that was tested is not properly 64-bit aligned.")
|
|
}
|
|
}()
|
|
|
|
link := Link{}
|
|
|
|
atomic.LoadInt64(&link.SrcLatency)
|
|
atomic.LoadInt64(&link.DstLatency)
|
|
atomic.LoadInt64(&link.Cost)
|
|
}
|
|
|
|
func TestLifecycle(t *testing.T) {
|
|
linkController := NewLinkManager(nil)
|
|
|
|
r0 := NewRouter("r0", "", "", 0, true)
|
|
r1 := NewRouter("r1", "", "", 0, true)
|
|
l0 := &Link{
|
|
Id: "l0",
|
|
Src: r0,
|
|
DstId: r1.Id,
|
|
}
|
|
l0.Dst.Store(r1)
|
|
|
|
linkController.Add(l0)
|
|
assert.True(t, linkController.has(l0))
|
|
|
|
links := r0.routerLinks.GetLinks()
|
|
assert.Equal(t, 1, len(links))
|
|
assert.Equal(t, l0, links[0])
|
|
|
|
links = r1.routerLinks.GetLinks()
|
|
assert.Equal(t, 1, len(links))
|
|
assert.Equal(t, l0, links[0])
|
|
|
|
linkController.Remove(l0)
|
|
assert.False(t, linkController.has(l0))
|
|
|
|
links = r0.routerLinks.GetLinks()
|
|
assert.Equal(t, 0, len(links))
|
|
|
|
links = r1.routerLinks.GetLinks()
|
|
assert.Equal(t, 0, len(links))
|
|
}
|
|
|
|
func TestNeighbors(t *testing.T) {
|
|
linkController := NewLinkManager(nil)
|
|
|
|
r0 := NewRouterForTest("r0", "", nil, nil, 0, true)
|
|
r1 := NewRouterForTest("r1", "", nil, nil, 0, true)
|
|
l0 := NewTestLink("l0", r0, r1)
|
|
l0.SetState(Connected)
|
|
linkController.Add(l0)
|
|
|
|
neighbors := linkController.ConnectedNeighborsOfRouter(r0)
|
|
assert.Equal(t, 1, len(neighbors))
|
|
assert.Equal(t, r1, neighbors[0])
|
|
}
|