V0.6.1 Arroyo Toad
This commit is contained in:
parent
5d5cc7ef0a
commit
0c294045dc
@ -26,7 +26,7 @@ public actor IoTSimulatorCore {
|
||||
|
||||
// schedule work
|
||||
let task = IoTSimulatorCore.schedule(envID: environment.location, deviceID: device.deviceID) { msg in
|
||||
print("\(msg.description)\n\n")
|
||||
//print("\(msg.description)\n\n")
|
||||
} failure: {
|
||||
print("Something is wrong")
|
||||
}
|
||||
@ -47,6 +47,12 @@ public actor IoTSimulatorCore {
|
||||
return IoTSimulatorCore.devices[devID]
|
||||
}
|
||||
|
||||
public static func nukeAll() {
|
||||
for value in IoTSimulatorCore.dev_tasks {
|
||||
value.value.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
private static func schedule(
|
||||
envID: sending String,
|
||||
deviceID: sending String,
|
||||
@ -55,9 +61,13 @@ public actor IoTSimulatorCore {
|
||||
) -> Task<(), Never> {
|
||||
return Task {
|
||||
|
||||
while true {
|
||||
let dev = IoTSimulatorCore.getDev(devID: deviceID)!
|
||||
let env = IoTSimulatorCore.getEnv(name: envID)!
|
||||
var notCancelled: Bool = true
|
||||
|
||||
let dev = IoTSimulatorCore.getDev(devID: deviceID)!
|
||||
let env = IoTSimulatorCore.getEnv(name: envID)!
|
||||
|
||||
while notCancelled {
|
||||
usleep(__useconds_t(dev.dutyCicle * 1000))
|
||||
|
||||
let message = dev.work(envrionment: env)
|
||||
do {
|
||||
@ -65,8 +75,18 @@ public actor IoTSimulatorCore {
|
||||
} catch {
|
||||
failure()
|
||||
}
|
||||
usleep(__useconds_t(dev.dutyCicle * 1000))
|
||||
|
||||
do {
|
||||
try Task.checkCancellation()
|
||||
} catch {
|
||||
notCancelled = false
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print("Bye, Bye, \(dev.deviceID)\n\n")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -63,3 +63,55 @@ import Testing
|
||||
sleep(15)
|
||||
|
||||
}
|
||||
|
||||
@Test func stressLoop1() async throws {
|
||||
|
||||
let devices: Int = 1000
|
||||
|
||||
let env = PhysicalEnvironment("Delta")
|
||||
let truth = PhysicalData(.Temperature, 22)
|
||||
|
||||
env.setPhysicalData(DataType.Temperature, truth)
|
||||
|
||||
IoTSimulatorCore.addEnv(environment: env)
|
||||
|
||||
let signKeyPath = "./Private/privateKey.pem"
|
||||
|
||||
let privateKey = try pem2key(filePath: signKeyPath)
|
||||
|
||||
for i in 0..<devices {
|
||||
|
||||
let dev: EdgeDevice = EdgeDevice(
|
||||
deviceID: "EDG-00\(i)",
|
||||
dataType: .Temperature,
|
||||
disconnected: false,
|
||||
location: Location3D(20, 10, 0),
|
||||
dutyCicle: 200 + UInt.random(in: 1000...5000),
|
||||
sensors: [
|
||||
0: RealSensor(
|
||||
sensorID: 0, sensorType: .Temperature, faulty: false, meanNoise: 1, stdNoise: 3,
|
||||
quantizationBits: 3),
|
||||
1: RealSensor(
|
||||
sensorID: 1, sensorType: .Temperature, faulty: false, meanNoise: 1, stdNoise: 3,
|
||||
quantizationBits: 3),
|
||||
2: RealSensor(
|
||||
sensorID: 2, sensorType: .Temperature, faulty: false, meanNoise: 1, stdNoise: 3,
|
||||
quantizationBits: 3),
|
||||
],
|
||||
privateKey: privateKey
|
||||
)
|
||||
|
||||
try IoTSimulatorCore.addDevice(location: "Delta", device: dev)
|
||||
}
|
||||
|
||||
let _sleep = 15
|
||||
|
||||
for i in 0..<_sleep {
|
||||
print("Hi, at \(i)s\n\n")
|
||||
sleep(1)
|
||||
}
|
||||
print("NUKE EM ALLLLLLLLLL!!!!!\n\n")
|
||||
IoTSimulatorCore.nukeAll()
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user